WordPress.org

Support

Support » How-To and Troubleshooting » blog page template not used for page 2

blog page template not used for page 2

Viewing 3 replies - 1 through 3 (of 3 total)
  • Talking to myself in here again, but maybe someone else will benefit. The problem was that my main blog is now on a page, and pages are aparently assumed to have only one post, so &paged=2 returned no posts instead of the one post for that page. I solved the problem in my .htaccess file with these lines:


    RewriteRule ^(blog)/page/?([0-9]{1,})/?$ /index.php?pagename=$1&pgd=$2 [QSA,L]
    RewriteRule ^(blog)(/[0-9]+)?/?$ /index.php?pagename=$1&pgd=$2 [QSA,L]

    The key is using ‘pgd’ instead ‘paged’, so the initial query returns the one bogus post for page ‘blog’, and the blog.php template is correctly used. Then, in that template:


    <?php $qy = preg_replace('/page_id=d*&?/','',$_SERVER['QUERY_STRING']); ?>
    <?php $qy = preg_replace('/pagename=w*&?/','',$qy); ?>
    <?php $qy = preg_replace('/page=w*&?/','',$qy); ?>
    <?php $qy = preg_replace('/pgd=(d*)(&?)/','paged=${1}${2}',$qy); ?>
    <?php $qy = $qy==''?'orderby=date':$qy; ?>
    <?php query_posts($qy); ?>
    <?php extract ($wp_query->query_vars); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    Here I turn the ‘pgd’ back to ‘paged’ for the real query that pulls up my blog posts. I included the beginning of The Loop for context. The extract() call is necessary to get posts_nav_links() to work later in the template.

    ColourDreamer
    Member

    @colourdreamer

    Where is that code used? And I don’t use “?” in my URLs.

    renatotarga
    Member

    @renatotarga

    The solution described above didn’t work for a website I developed: http://www.anacarmen.com

    Some small changes were necessary if you used the blog.php as described in http://codex.wordpress.org/Pages

    Instead of index.php, I used blog.php in the .htaccess file.

    RewriteRule ^(blog)/page/?([0-9]{1,})/?$ /blog.php?pagename=$1&pgd=$2 [QSA,L]
    RewriteRule ^(blog)(/[0-9]+)?/?$ /blog.php?pagename=$1&pgd=$2 [QSA,L]

    And I replaced the original code in blog.php with

    <?php $qy = preg_replace('/page_id=d*&?/','',$_SERVER['QUERY_STRING']); ?>
    <?php $qy = preg_replace('/pagename=w*&?/','',$qy); ?>
    <?php $qy = preg_replace('/page=w*&?/','',$qy); ?>
    <?php $qy = preg_replace('/pgd=(d*)(&?)/','paged=${1}${2}',$qy); ?>
    <?php $qy = $qy==''?'orderby=date':$qy; ?>
    <?php query_posts($qy);
    extract ($wp_query->query_vars);
    load_template( TEMPLATEPATH . '/index.php'); //loads index
    ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘blog page template not used for page 2’ is closed to new replies.