WordPress.org

Ready to get started?Download WordPress

Forums

blog page template not used for page 2 (4 posts)

  1. Dylan Kuhn
    Member
    Posted 9 years ago #

    Hi,

    I have a CMS setup using the Page-To-Front plugin and WP 1.5.1. Right now I have a 'home' page that uses the generic page.php template, and 'blog' page that uses a specific blog.php template. This works great for page 1, but when the 'Next Page' is clicked in the blog, it goes back to the page.php template. Take a look:

    http://www.cyberhobo.net/index.php?pagename=blog&paged=1

    http://www.cyberhobo.net/index.php?pagename=blog&paged=2

    Anyone know why this happens? I don't see any code in the Page-To-Front plugin that would do that.

  2. Dylan Kuhn
    Member
    Posted 8 years ago #

    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.

  3. ColourDreamer
    Member
    Posted 8 years ago #

    Where is that code used? And I don't use "?" in my URLs.

  4. renatotarga
    Member
    Posted 7 years ago #

    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
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags