WordPress.org

Ready to get started?Download WordPress

Forums

title question (6 posts)

  1. spitstatic
    Member
    Posted 9 years ago #

    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?

  2. Kafkaesqui

    Posted 9 years ago #

    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.

  3. spitstatic
    Member
    Posted 9 years ago #

    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.

  4. spitstatic
    Member
    Posted 9 years ago #

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

  5. spitstatic
    Member
    Posted 9 years ago #

    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>

  6. spitstatic
    Member
    Posted 9 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic