'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
Astra_Builder_UI_Controller::render_customizer_edit_button( 'row-editor-shortcut' );
} else {
echo '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
do_action( 'astra_related_posts_title_before' );
if ( '' !== $related_posts_title ) {
echo apply_filters( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'astra_related_posts_title',
sprintf(
'
<%1$s class="ast-related-posts-title"> %2$s %1$s>
',
apply_filters( 'astra_related_posts_box_heading_tag', 'h2' ),
$related_posts_title
)
);
}
do_action( 'astra_related_posts_title_after' );
echo '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
$related_posts_section_loaded = true;
}
?>
>
astra_get_related_post_featured_image( $post_id );
do_action( 'astra_related_post_after_featured_image', $post_id );
} else {
?>
astra_get_related_post_excerpt( $post_id );
$this->astra_get_related_post_read_more( $post_id );
?>
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
do_action( 'astra_related_posts_loop_after' );
}
}
/**
* Render Post CTA button HTML marup.
*
* @param int $current_post_id current post ID.
*
* @since 3.5.0
*/
public function astra_get_related_post_read_more( $current_post_id ) {
if ( ! astra_get_option( 'enable-related-posts-excerpt' ) ) {
return;
}
$related_posts_content_type = apply_filters( 'astra_related_posts_content_type', 'excerpt' );
if ( 'full-content' === $related_posts_content_type ) {
return;
}
$target = apply_filters( 'astra_related_post_cta_target', '_self' );
$cta_text = apply_filters( 'astra_related_post_read_more_text', astra_get_i18n_option( 'blog-read-more-text', _x( '%astra%', 'Blogs: Read More Text', 'astra' ) ) );
$blog_read_more_as_button = astra_get_option( 'blog-read-more-as-button' );
$show_read_more_as_button = apply_filters( 'astra_related_post_read_more_as_button', $blog_read_more_as_button );
$class = '';
if ( $show_read_more_as_button ) {
$class = 'ast-button';
}
$custom_class = apply_filters( 'astra_related_post_cta_custom_classes', $class );
do_action( 'astra_related_post_before_cta', $current_post_id );
?>
< class="ast-related-post-title entry-title">
>
$alt_text ? $alt_text : get_the_title( $current_post_id ),
'itemprop' => apply_filters( 'astra_related_posts_thumbnail_itemprop', '' ),
)
)
);
$appended_class = has_post_thumbnail( $current_post_id ) ? 'post-has-thumb' : 'ast-no-thumb';
$featured_img_markup = '
';
if ( '' !== $post_thumb ) {
$featured_img_markup .= '
';
}
$featured_img_markup = apply_filters( 'astra_related_post_featured_image_after', $featured_img_markup );
$featured_img_markup .= '
';
$featured_img_markup = apply_filters( 'astra_related_post_thumbnail', $featured_img_markup, $before, $after );
if ( false === $echo ) {
return $before . $featured_img_markup . $after;
}
echo $before . $featured_img_markup . $after; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Get related posts based on configurations.
*
* @param int $post_id Current Post ID.
*
* @since 3.5.0
*
* @return WP_Query|bool
*/
public function astra_get_related_posts_by_query( $post_id ) {
$term_ids = array();
$current_post_type = get_post_type( $post_id );
$related_posts_total_count = absint( astra_get_option( 'related-posts-total-count', 2 ) );
// Taking one post extra in loop because if current post excluded from while loop then this extra one post will cover total post count. Apperently avoided 'post__not_in' from WP_Query.
$updated_total_posts_count = $related_posts_total_count + 1;
$related_posts_order_by = astra_get_option( 'related-posts-order-by', 'date' );
$related_posts_order = astra_get_option( 'related-posts-order', 'desc' );
$related_posts_based_on = astra_get_option( 'related-posts-based-on', 'categories' );
$query_args = array(
'update_post_meta_cache' => false,
'posts_per_page' => $updated_total_posts_count,
'no_found_rows' => true,
'post_status' => 'publish',
'post_type' => $current_post_type,
'orderby' => $related_posts_order_by,
'fields' => 'ids',
'order' => $related_posts_order,
);
if ( 'tags' === $related_posts_based_on ) {
$terms = get_the_tags( $post_id );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$term_ids = wp_list_pluck( $terms, 'term_id' );
}
$query_args['tag__in'] = $term_ids;
} else {
$terms = get_the_category( $post_id );
/** @psalm-suppress RedundantConditionGivenDocblockType */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
/** @psalm-suppress RedundantConditionGivenDocblockType */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
$term_ids = wp_list_pluck( $terms, 'term_id' );
}
$query_args['category__in'] = $term_ids;
}
$query_args = apply_filters( 'astra_related_posts_query_args', $query_args );
return new WP_Query( $query_args );
}
}
/**
* Kicking this off by creating NEW instance.
*/
new Astra_Related_Posts_Markup();