WordPress.org

Support

Support » Themes and Templates » [Resolved] custom page template for blog page

[Resolved] custom page template for blog page

  • 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
    Paul

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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:
    http://123west.net/wordpress/

    esmi

    @esmi

    Forum Moderator

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

    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.

    esmi

    @esmi

    Forum Moderator

    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.

    Ah yes. fixed!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] custom page template for blog page’ is closed to new replies.
Skip to toolbar