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

General Discussion

Displayiin Custom Posts and Fields in a Template Problem

I had this issues 6 months ago and never got enough help to move on. I have gone over the first three sections of How to build a website theme and get stuck at the same place each time. My trouble starts with the Displaying Customs Posts and Fields in a Template at the 1:28 mark and runs until the 4:12 mark when my titles do not display. Below is my code: <?php

/*

Template Name: Work Page

*/

get_header(); ?>

<p>This is 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><?php the_title(); ?><h3>
<?php the_content(); ?>
<hr>

<?php endwhile; else: ?>

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

<?php endif; ?>

<?php get_footer(); ?>

I need to know where the titles of Stop Visual Pollution, Dr. Waltz, Smells Like Bakin', and Shirts 4 Mike are supposed to be placed into the code and where is the the_query actually pulling the content from. I am not sure if it has anything to do with the html.prototype folder and the work.html file. Just like six months ago, I am here now for the third time, so any help would be appreciated. Larry

3 Answers

Hi Larry Wright

Are you aware that your h3 isn't being closed properly?

From your question, you don't mention if the_content() is or is not being displayed?

I corrected that problem but it didn't bring up my titles on the localhost/allisongrayce.com/work page. The page says this is the header, lists the navigation bar of home, about, blog, contact, and work; then says below that this is the work.php file; and below that this is the footer. I do appreciate your help. I had already erased everything and put it back in three times and missed that header tag. Thanks again.

I have figured out that the information I want to display is in the work-projects.txt file but I don'[t know where the file needs to be placed to be read.
This file has all the titles of Stop Visual Pollution, Dr. Wattz, etc. as well as the description, background color, and color button. I apparently missed a step somewhere but I have never seen this file in the wpportfolio folder we created with all of the other files. And I could also be completely wrong, I just don't know. Thanks for any help!