1

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(); ?>

2 Answers 2

1

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.

0
1

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

6
  • I've been told not to use index.php for this purpose? Or was that incorrect direction? Commented Sep 11, 2012 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
    Commented Sep 11, 2012 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? Commented Sep 11, 2012 at 16:48
  • yes, that's correct
    – Milo
    Commented Sep 11, 2012 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? Commented Sep 11, 2012 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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