Hiya nice WordPress builders, I wish to record posts from a specif class within the 2nd or center paragraph of the publish.
I attempted including some scripts to my perform.php to attain that, however I could not get the 2nd or center paragraph of the article, which is the important thing half, to work.
perform custom_related_posts( $content material ) {
world $publish;
$current_post_id = get_the_ID();
$html = '';
if ( is_singular( 'publish' ) ) {
//get the classes of the present publish
$cats = get_the_category( $current_post_id );
$cat_array = array();
foreach ( $cats as $key1 => $cat ) {
$cat_array[ $key1 ] = $cat->slug;
}
//get the tags of the present publish
$tags = get_the_tags( $current_post_id );
$tag_array = array();
foreach ( $tags as $key2 => $tag ) {
$tag_array[ $key2 ] = $tag->slug;
}
$related_posts = new WP_Query(
array(
'post_type' => 'publish',
'post_status' => 'publish',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'class',
'area' => 'slug',
'phrases' => $cat_array
),
array(
'taxonomy' => 'post_tag',
'area' => 'slug',
'phrases' => $tag_array
)
),
'showposts' => 6,
'post_type' => array( 'publish' ),
'category_name' => 'songs',
'orderby' => 1
)
);
if ( $related_posts->have_posts() ) {
$html .= '<div class="related-posts"><h3>Associated posts</h3><ul class="related_post wp_rp"> ';
whereas ( $related_posts->have_posts() ) {
$related_posts->the_post();
$html .= '<li data-position="0" data-poid="in-215276" data-post-type="none"><a rel="bookmark" class="wp_rp_thumbnail" href="';
$html .= get_the_permalink();
$html .= '">';
if ( has_post_thumbnail( $post->ID ) ) {
$picture = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
$html .= '<img class="featured-image" src="' . esc_url( $image[0] ) . '">';
}
$html .= '<a category="wp_rp_title" fashion="color:#333333" href="';
$html .= get_the_permalink();
$html .= '">';
$html .= '' . get_the_title() . '';
$html .= '</a>';
$html .= '</li>';
}
$html .= '</ul></div>';
wp_reset_postdata();
} else {
$html .= '<div class="related-posts">' . esc_html__( 'No associated posts have been discovered.', 'textdomain' ) . '</div>';
}
$content material .= $html;
}
return $content material;
}
add_filter( 'the_content', 'custom_related_posts' );
Put up hyperlink: https://www.voxlyrics.com/drake-fountains-ft-tems/