Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
1  
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
add comment

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
add comment

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.