WordPress.org

Support

Support » Themes and Templates » title question

title question

  • I have this page: http://mguthrie.net/portfolio

    Then that has subpages such as this page: http://mguthrie.net/portfolio/photography

    Now, on the main Portfolio page, the h2 displays the title as “portfolio” which is correct.

    But on the photography, the h2 displays the title as “photography”. I know that it’s just displaying a title there, but I would rather it still say Portfolio.

    I would rather not have to hardcode the headers in. Can anyone tell me if there is a way to tell subpages to display the parent header but not effect the parent pages?

Viewing 5 replies - 1 through 5 (of 5 total)
  • This bit of PHP captures the post ID of the parent Page and (if it exists) uses that to query the database for the parent’s title:

    <?php rewind_posts();
    the_post();
    $title = $post->post_title;
    $parent_ID = $post->post_parent;
    rewind_posts();
    if($parent_ID) {
    $title = $wpdb->get_var("SELECT post_title from $wpdb->posts WHERE ID = $parent_ID");
    }
    echo $title;
    ?>

    The multiple instances of rewind_posts() is to avoid conflicting with other post (or rather, Page) loops in your template.

    Thanks!

    However, I tried it, and it seems to load extremely slow when I load a page, and when it finally finishes, it goes to the front page instead of the page. The same happens when I try going to a subpage.

    Any ideas?

    thanks so much for your help.

    I’m going to temporily put ‘<?php the_title(); ?>’ back for now.

    I figured out a way!

    <h2><?php if (is_page('photography')) { echo "portfolio"; }
    elseif (is_page('design')) {echo "portfolio"; }
    elseif (is_page('other')) {echo "portfolio"; }
    else {the_title();} ?></h2>

    Note: I know it’s not very convenient having to put an instance in for each page, but it’s the only way I knew how to get this done in the time I needed it done.

    Please continue to share, however, if you have a better method.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘title question’ is closed to new replies.