display only the second level categories in the category list

QuestionsCategory: Free WordPress Theme ClubFitnessdisplay only the second level categories in the category list
A. A. asked 12 months ago

On every archive page and the front page, there is this category list in the top left corner of each post item.
How do I make only the second level categories appear in the list? Is it possible?
If not, the second best thing would be to display only the top level categories there. How do i achieve that?

Thank you!

1 Answers
thewpclub Staff answered 12 months ago

Hello,
I don’t know how to show the second category but if you want only one category you have to edit the page loop.php at line 42. Replace it with:

<?php $category = get_the_category(); ?>
<?php if ( $category[0] ) { ?>
<ul class="post-categories">
<li><a href="<?php echo get_category_link( $category[0]->term_id ); ?>"><?php echo $category[0]->cat_name; ?></a></li>
</ul>
<?php } ?>