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

PHP How to Build a WordPress Theme WordPress Theme Functions Displaying Custom Posts and Fields in a Template

Getting The Work Page to Display Properly

Everything is working so far, except my work page. I have one project that I threw up for an example, and I am pretty sure I did the code right but my <hr> isn't showing up. And when I have my project published it makes my footer disappear and the project doesn't actually show up on the page.

If I put the project in draft, then my footer reappears but no horizontal line.

This is the code for my work.php page and then the single-work.php page:

<?php 
/*

    Template Name: Work Page

*/
get_header(); ?>
<p>This this the work.php file.</p>
<?php 

    $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' ); ?>
    <hr>

<?php endwhile; else: ?>
<p> There are no posts or pages here.</p>
<?php endif; ?> 
<?php get_footer(); ?>
<?php get_header(); ?>

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

Did I miss something in the code? Or did I maybe set something up wrong on the admin side?

sorry for the formatting - I can't get it to get everything in...

** fixed it **

1 Answer

I think you might be missing a closing quote and > on this line:

 <h3><a href="<?php the_permalink(); ?><?php the_title(); ?></a></h3>

Should be

 <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

Does that help at all?

EDIT: updated code, moved the_title() to inside the anchor tag. I think this is right now...

Thanks so much for your help. It's a lot of help having a second pair of eyes to see what I don't!