Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Keifer Szurszewski
Keifer Szurszewski
5,906 Points

New posts using page.php template, instead of single.php

I've been using the "Create a WordPress Theme" course to create my own theme. It's generally worked okay, except for one huge problem: when I create a new post, it is somehow directing to the page.php template. It seems to work fine for the first 2 posts, but after I have more than 2 posts total, it starts using the Page.php template. Here's the site I'm working on:

http://www.minimalgifts.com

Notice how the first two images (Amazon Giftcard and Bamboo) are using the page.php template, while the other two images are using the single.php template. Navigating to the URL directly also doesn't work:

http://minimalgifts.com/bamboo/

http://minimalgifts.com/amazon-giftcard/

Any idea on what to fix? My code is below; I tried using Markdown but it wouldn't format correctly, sorry!


Functions.php

<?php

// Load the Theme CSS function theme_styles() {

wp_enqueue_style( 'normalize', get_template_directory_uri() . '/css/normalize.css' );

wp_enqueue_style( 'grid', get_template_directory_uri() . '/css/grid.css' ); wp_enqueue_style( 'googlefonts', 'http://fonts.googleapis.com/css?family=Indie+Flower' ); wp_enqueue_style( 'main', get_template_directory_uri() . '/style.css' ); }

add_action( 'wp_enqueue_scripts', 'theme_styles' );

add_theme_support( 'post-thumbnails' );

?>


Home.php

<?php get_header(); ?> <div class="wrapper clearfix"> <div class="grid-12 photos" id="photos"> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class="post-square"> <a href="<?php the_permalink(); ?>"> <div class="home-thumb"> <?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?> </div> </a> </div> <?php endwhile; else: ?> <p>There are no posts or pages here</p> <?php endif; ?> </div> <?php get_footer(); ?>


Page.php

<?php get_header() ?> <p>This is the page.php template.</p> <?php get_footer() ?>


Single.php

<?php get_header(); ?> <div class="wrapper clearfix"> <div class="grid-12 item-info"> <?php while ( have_posts() ) : the_post(); ?> <?php the_content(); ?> <?php endwhile; ?> </div </div>

<?php get_footer(); ?>


Thanks!

2 Answers

Brett Smith
Brett Smith
4,261 Points

I noticed your home.php file lists calls the loop using "if" and "while" but your single.php file does not. I'm also a little confused as to how your page.php is generating content as it does not include the WordPress Loop.

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <?php the_content(); ?>

<?php endwhile; endif; ?>
Keifer Szurszewski
Keifer Szurszewski
5,906 Points

Thanks for replying. I've changed both the single.php file and the home.php file to include "if" in the loop. Still not working.