Displaying page parent title on search result page? (1 post)

  1. urbanty
    Posted 3 years ago #


    on my search results page, I would like to display the parent's title of pages. I'm doing the same with the categories of posts.
    The idea is, that the visitors can directly see, where this page (or post) belongs.

    My code so far looks like this:

    <?php if(have_posts()): ?><?php while ( have_posts() ) : the_post(); ?>
    		if (is_page()){
    			$parent_title = get_the_title($post->post_parent);
    			$parent_link = get_permalink($post->post_parent);
    			<a href="<?php echo $parent_link; ?>" title="<?php echo $parent_title; ?>"><?php echo $parent_title; ?> &rarr;</a>
    $category = get_the_category();
    echo ' <a href="' . get_category_link($category[0]->cat_ID) . '" title="' . $category[0]->name . '">' . $category[0]->name . ' &rarr;</a>';?></h1>
    <?php } ?>

    Displaying the categories works fine. But for the search results which are pages, displaying the page's parent doesn't work.

    Can anyone help?

    Thanks! :)

Topic Closed

This topic has been closed to new replies.

About this Topic