Ready to get started?Download WordPress


[resolved] custom page template for blog page (6 posts)

  1. Paul de Wouters
    Human Made
    Posted 3 years ago #

    I think I've confused myself by spending too much time on this.
    I've set up some body classes that control the page layout, so for example <body class="2-sidebars-left"> and this is controlled by a drop down meta box field in the pages write panel.
    Now, this works fine for all pages except the blog page. This is because I set a static page for 'Home' and I set a 'blog' page to be the 'posts page'. It then uses index.php and ignores my custom field settings or page template.
    To work around this, I created a new page template with a WP_Query

    <?php $temp = $wp_query;
    $wp_query= null; ?>
    <?php $wp_query = new WP_Query(); ?>
    <?php $wp_query->query('posts_per_page=5'.'&paged='.$paged); ?>
    <?php while ( $wp_query->have_posts() ) : $wp_query->the_post() ?>

    ...the loop...
    <?php $wp_query = null; $wp_query = $temp;?>
    I got the code from here :http://weblogtoolscollection.com/archives/2008/04/13/define-your-own-wordpress-loop-using-wp_query/

    It works, but I'm wondering if it's the best way to do it, and if it doesn't have any side effects or something.

    thanks for any suggestions

  2. photocurio
    Posted 3 years ago #

    I'm having a similar issue. I did not use wp_query though. I just made a static Home page and a blank page for blog posts (called News). My problem is that the News page loads the Home page template. Why does it do that??

    Site is here:

  3. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    That is the default behaviour when you have a static Home page. Your designated Posts page uses the index.php template file.

  4. photocurio
    Posted 3 years ago #

    Hey Esmi, my problem is that my post page is not loading my index.php. It is loading my home.php, which I've designated as my home page.

  5. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    If your Home page is a static page, try renaming home.php to something like home-page.php. The filename home.* is a special case on some systems.

  6. photocurio
    Posted 3 years ago #

    Ah yes. fixed!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.