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

single-work.php is blank

Hey everyone. Just to make sure I had all the code correct i swapped out my file with the project file. when I click on a link on my work page, the single post page is completely blank. I do not even see the else message. I am having a trouble with the using post name links and have to use default for anything to work (i am on wamp and have a separate thread open on this) and I am wondering if that has something to do with it. Could anyone point me in the right direction? Thanks!

        <?php get_header(); ?>

<p>This is the single-work.php file.</p>

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

<h3><?php the_title() ;?></h3>  
<?php the_field( 'description' ); ?>
<hr>

<?php endwhile; else: ?>

<p>There are no posts or pages here</p>

<?php endif; ?>

<?php get_footer(); ?>

Benjamin Bornschein
Benjamin Bornschein
1,364 Points

Can you confirm, that your WAMP is running? Is error reporting set to E_ALL?

It is running and all the other pages are working correctly but for some reason the single page wont pull up. I am not too familiar with wamp settings. How would I check on this? I know I get errors when there are errors but I am not sure if this is an error or a setting I need to change.

Benjamin Bornschein
Benjamin Bornschein
1,364 Points

Can you write "blablabla" in your single-work.php file to check, if the file is loaded?

1 Answer

Kevin Korte
Kevin Korte
28,149 Points

So if this template is single-work.php than according to the Wordpress template hierarchy this template is used for single post pages, for custom posts, in this case a post type of "work". However, you're not querying a a custom post type or work, you're only querying the default post type.

I believe this is what you're problem is. Do you have a custom post type name "work" set up?

If you're trying to query the default post, this template either needs to be called single-post.php or just single.php.

If you're truly trying to query a custom post type of work, than you need to change your query to look something more like

 $query = new WP_Query( 'post_type=work' );

 if ($query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();

Make sure you are following the template hierarchy correctly.

WP template

I do have a custom post type for work and this is supposed to be the single post page for the single posts on the work.php page in the video it is stated that this does not need the query because it will be pulling from the page that had the post.