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.

I'm building a search results template and want to display the parent section of the website for each result returned. so at the bottom of each search result excerpt it'd say "Found in [section] | Reacd More"

Something like: http://www.foxglovecovert.org.uk/search/results/search&keywords=local/

share|improve this question
    
How are you defining "section"? Category, parent page, template, something super cool that I don't even know exists? –  Matthew Boynes Jan 28 '12 at 15:33
    
I'd like "blog", "gallery"(custom post format), "event"(custom post format), "about"(parent page) –  Bent Jan 28 '12 at 19:59
add comment

2 Answers

up vote 0 down vote accepted

For your custom post types and your blog, you can use get_post_type(). For your About parent page, if the pages only go one level deep, you can check $post->post_parent to see if it's the about page. Otherwise, you can use get_post_ancestors() and check that array to see if your About page is in it!

share|improve this answer
    
Thanks. I think I can write the function I need from here. –  Bent Jan 28 '12 at 20:48
add comment
function my_get_highest_parent( $id ) {
    $cat = get_category( $id );
    $parent = $cat->parent;

    if( $parent == 0 ) 
        return $id;
    else
        my_get_highest_parent( $parent );
}

That will get you the highest level parent (the category with parent 0) based on the category-id you feed into it

share|improve this answer
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.