Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

like if a post in put in leevel3 category level 1-> level 2 -> level3 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?? – robert leo Jan 14 at 15:30

1 Answer

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>
<ul>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php
    $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; ?>
</ul>

.

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

 
discard

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.