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


20,999 Points

Building a Wordpress theme question: problem on the 'Work.php' page


I am following the tutorials for building a wordpress theme and my work.php page does not show any posts. Here's the code on my text editor:

    Template Name: Work Page
get_header(); ?>
<p>This is the work.php</p>
    $args = array(  
        'post_type' => 'work' 
    $the_query = new WP_Query( $args );
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    <?php the_field( 'description' ); ?>
<?php endwhile; else: ?>
<p>There are no posts or pages to display.</p>
<?php endif; ?> 
<?php get_footer(); ?>

And here is the output of the browser (on localhost)

<p>This is the header</p>
<div class="menu-main-menu-container"><ul id="menu-main-menu" class="menu"><li id="menu-item-27" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-27"><a href="http://localhost/valeriuvetiul.com/">Home</a></li>
<li id="menu-item-28" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-28"><a href="http://localhost/valeriuvetiul.com/?page_id=6">About</a></li>
<li id="menu-item-29" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-29"><a href="http://localhost/valeriuvetiul.com/?page_id=9">Blog</a></li>
<li id="menu-item-31" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-11 current_page_item menu-item-31"><a href="http://localhost/valeriuvetiul.com/?page_id=11">Work</a></li>
<li id="menu-item-30" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-30"><a href="http://localhost/valeriuvetiul.com/?page_id=13">Contact</a></li>
<p>This is the work.php</p>
<p>This is the footer</p>

As you can see, there is nothing between the 'This is the work.php' and 'This is the footer'.

Help is much appreciated.

Regards, Valeriu

3 Answers

20,999 Points

I found the answer - there were no projects to display. I should have created them. I either missed a piece in a video somewhere, or this was not mentioned in the tutorial.

20,999 Points

Related question:

In the tutorial, we change the permalink structure from default to post name. As soon as I do it, all pages aside from homepage don't show - 404 Not found error:

Not Found: The requested URL /XYZ.com/about/ was not found on this server.

It does however display as: http://localhost/XYZ.com/?page_id=6

Any ideas?

You could check if you have mod_rewrite enabled.

Locate httpd.conf on your local server (I'm using XAMPP right now) and find the following line: (This is from my file, my permalinks are working)

LoadModule rewrite_module modules/mod_rewrite.so

Comment it out (remove the # in front of it) to enable.