Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a site using a static homepage, and a posts page called Press(press.php). The template is being pulled up correctly, however no posts are shown. Any ideas why? Thanks in advance.

Live site.

press.php

<?php
/*
Template Name: Press
*/
?>


<?php get_header(); ?>

<div id="logo">
    <a href="<?php bloginfo('url'); ?>"><img src="<?php echo get_template_directory_uri(); ?>/img/parlour_side.png" alt="Parlour Salon logo" id="logo" /></a>
</div><!-- end logo -->

<div id="main">
    <div class="content">
        <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <?php the_content('read more...'); ?>
            <p><?php the_date(); ?></p>
        <?php endwhile; ?>
        <?php else : ?>
                <p>I'm not sure what you're looking for.</p>
        <?php endif; ?>
    </div><!-- end content -->

<?php get_footer(); ?>
share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

Make a copy of press.php and rename it to home.php.

The page you selected "Press" to be the designated page for your posts in the dashboard under,

Settings > Reading > Posts Page: [Press]

...now falls under the control of the template hierarchy as listed by Milo.

First WordPress will look for the existence of home.php and if it exists, that will be applied as the template for your Press page.

If it does not exist, it will then move onto the default index.php and do the same.

Effectively your press.php is useless with regards to your Press page while it remains set under your Settings > Reading preferences.

Usually when creating custom themes my index.php looks something similar to,

<?php get_header(); ?>

<?php 

    if(is_home() ) {

    include 'homepage.php';

    } else {

    //do as you wish here... i.e. display normal loop etc

   } 

?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

homepage.php for example would be your custom home page, as a result you don't need to use any of the settings in reading. This is only a very simplistic overview of something that can be done a number of ways, but just trying to give you an idea.

However for now, what you want is to be using home.php as described above.

share|improve this answer
    
perfecto, thanks! –  user1255049 Sep 11 '12 at 16:56
add comment

When you designate a page to be the page for posts, it's no longer a "page" in the conventional sense, and will not use the template assigned to it.

Check the Template Hierarchy to see how WordPress selects a template for this page:

Home Page display

home.php

index.php

share|improve this answer
    
I've been told not to use index.php for this purpose? Or was that incorrect direction? –  user1255049 Sep 11 '12 at 16:25
    
index.php is the fallback template for every content type, so if you want it specific to this page it's probably best to use home.php. this image shows the template loader flow, notice they all resolve to index.php if a more specific template is not found. –  Milo Sep 11 '12 at 16:47
    
So, if I change press.php to home.php and remove the Template Name, the reassign settings in WP admin the loop will work? –  user1255049 Sep 11 '12 at 16:48
    
yes, that's correct –  Milo Sep 11 '12 at 16:50
    
Ok, thanks. When I'm in WP admin (Settings > Reading) I have Static Home Page selected, then Front Page=Home, what do I select for Posts Page? –  user1255049 Sep 11 '12 at 16:53
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.