I am trying to create a related post section at the bottom of each post. I am using YARPP plugin to generate the related posts. I want customise the a template to show, a thumbnail(Done), title(Done) and a specific category(Issue).
My issue is its displaying all assigned categories, I only want to display one child category. I have a speaker category with child categories of the names of the speakers.
Let me know if you need more information. Thanks
<h3>Related Posts</h3>
<?php if ( have_posts() ) : ?>
<div>
<?php
while ( have_posts() ) : the_post(); ?>
<div>
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail( $dimensions['size'], array( 'data-pin-nopin' => 'true' ) ); ?></a>
<a href="<?php the_permalink(); ?>" rel="bookmark norewrite" title="<?php the_title_attribute(); ?>">
</div>
<div>
<?php the_title(); ?>
<!-- How to add specific category -->
<?php
$categories = get_the_category();
$separator = ' ';
$output = '';
if ( ! empty( $categories ) ) {
foreach( $categories as $category ) {
$term_id = '328';
$output .= '|| <a href="' . esc_url( get_category_link( $category->term_id ) ) . '" alt="' . esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ) . '">' . esc_html( $category->name ) . '</a>' . $separator;
}
echo trim( $output, $separator );
}
?>
<!-- How to add specific category END -->
</div>
<?php endif; ?>
<?php endwhile; ?>
</div>
<?php else : ?>
<p>No related photos.</p>
<?php endif; ?>
328
? is that id for you want to display? – Bhautik