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.
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(); ?>
Make a copy of
press.php
and rename it tohome.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,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.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: