ThemeShaper Forums » Thematic

[closed]

page template returning incorrect title (fix included)

(1 post)
  • Started 4 years ago by mpedrummer
  • This topic is not resolved

Tags:

  1. mpedrummer
    Member

    Hi all - thanks for the framework, it's been making a lot of things easier for me. I'm migrating a large website from an old wiki to WordPress, and we're using Thematic. Once it's available publicly, I'll be sure to share!

    Anyway, part of the site is documentation, which means pages - lots of pages. I discovered a bug in the page.php template, or more specifically, in the function thematic_doctitle(). In the case that is_page() is true, it generates the doctitle using single_post_title(). This is the problem.

    Here's the issue - with multiple posts with the same post_name in the wp_posts table, single_post_title() returns the name of the first one it finds. This is not necessarily the correct one. This only happens with pages, it appears that at an application level, WP enforces uniqueness on this column when the post_type is 'post'.

    In WP's code, the comment for single_post_title() indicates that it's not supposed to be used for pages. The function uses get_query_var('p') to attempt to determine the ID of the page/post. If that variable is not present (it's not) then it uses get_query_var('name') instead, which causes the incorrect behavior.

    I figured out a simple way to get the correct ID into the cache of query variables.

    In the page.php template of your child theme, replace this line:
    <?php get_header() ?>

    with

    <?php
    // Call the_post() first to let WP resolve things correctly
    the_post();
    // Insert the ID as a query var
    $wp_query->set( 'p', get_the_ID() );
    get_header();
    ?>

    And it works! This isn't a "fix" per se, more of a bandaid/workaround, but it corrects the behavior.

    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.