WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Do anyone know how to display a category tree of a post in the search result.

Foe example: If a post is in level 3 category level 1-> level 2 -> level 3 where the level one is the parent one.

share|improve this question
Do you mean to ask that how to show category title and description in place of post title under that category in search result?? – user26004 Jan 14 '13 at 15:30

i am missing some details but here is the code for this string
"category level 1-> level 2 -> level3"...

i also included the search term as the title and the loop around it..

<h1><?php echo 'Search Results For:'. get_search_query(); ?></h1>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    $category = get_the_category(); 
    $catName = $category[0]->cat_name;
    $catFatherID = $category[0]->category_parent;
    $catFather = get_the_category_by_ID($catFatherID)
    <li class="result"><?php if($catFather){echo $catFather.'&raquo;';}; echo $catName.'&raquo;';the_title(); ?></li>

<?php endwhile; ?>
<?php endif; ?>


Hope This Helps ;)
Cheers, Sagive.

share|improve this answer
Nice but what about more then one level up and showing all posts in one tree instead of a tree for each post? – Bainternet Apr 1 '12 at 20:38
i dont think thats what he ask - or did i missunderstood? trying to give him to most easy to use easy to change code.. – Sagive SEO Apr 1 '12 at 20:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.