How to display the parent category in the archive?
-
I wanted to display the parent category name before the actual category in my archives page. It currently is:
<h1>Categoria: <b>"<?php echo single_cat_title(); ?>"</b></h1>
I googled and landed on this topic, suggesting that I replace
<?php echo single_cat_title(); ?>
for<?php if( $category->parent ) { echo get_the_category_by_ID($category->parent) . ' - '; } single_cat_title(); ?>
, but it didn’t work. It still shows only the child category name.I also tried
<?php echo get_the_category_by_ID($category->parent); ?> - <?php single_cat_title(); ?>
, but got an error saying “CATCHABLE FATAL ERROR: OBJECT OF CLASS WP_ERROR COULD NOT BE CONVERTED TO STRING IN /HOME/…/ARCHIVE.PHP ON LINE 8”How can I get something like:
<h1>Categoria: <b>"<parent category> - <?php echo single_cat_title(); ?>"</b></h1>
Thanks.
- The topic ‘How to display the parent category in the archive?’ is closed to new replies.