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

Displaying custom posts and templates

Hello there I'm wondering if I can get some help in regards to the end of stage III tutorial. It seems that there is content that I am missing as I have completed each portion of the work.php document. I'm not sure where I'm wrong in this case but I'm unable to continue the level as I am not showing what Zach shows at the end of stage 3 last video.

12 Answers

Matt Campbell
Matt Campbell
9,767 Points

Can you post up your code please and also give some more detail on what is and isn't showing up? What are you expecting it to do and what is it in fact not doing? Then we can help!

Thanks.

This is from the work.php page. I'm expecting to see the same results as Zac displays once he has completed this process. If you would like please got to the video second to last stage 3 and FF to 2:55 and you will see what I mean. However, in the meantime here's the 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_field( 'description' ); ?> <hr></hr>

<?php endwhile; else:?>

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

<?php endif; ?>

<?php get_footer(); ?>

Like I said I cannot move forward until I have figured this part out.

Hi David, I had the same problem but it was because I had not done a part of the project (not sure how I missed it but I did).

Have you added the two plugins required and configured them for your custom posts and pages? Here is the video that shows you what you need to do 'Adding Custom Content to the Site'.

The video shows you how to add the custom 'work' and 'testimonials' sections. I have not found the part for adding the content to these sections once configured though, so I copied the titles that show from the video you are currently on and added lorum ipsum for the descriptions for the time being.

I hope this helps.

Armando Tinoco
Armando Tinoco
1,154 Points

Had the same issue... This video is skipped over... How did you find it?

My apologies for the late response. Yes I have added the plug-ins. I'm a bit confused should I create projects and add that information? Also, I've noticed that there are horizontal rules under each work project. What do you recommend I do at this point? As I said before I cannot continue this course until I have completed this section. Thank you very much for your response it is helpful.

Hi David, a minor thing that I notice is that on your <?php endwhile; else:?> a space is needed <?php endwhile; else: ?>.

Also I'm not sure if it is before the video you are on or after, but the 'title' and 'description' need to have some html elements added to them:

<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_field( 'description' ); ?>
<hr>

This will bring in the horizontal rule you are missing.

Like I said I am not to sure where the content for the work and testimonials sections is but if you just fill what is needed with lorum iipsum as a placeholder for now you can carry on with the project as I have been doing so.

Hope this helps.

Sorry, hi again. If you download these project files and un-zip them, you'll see a folder called html-prototype. In this folder are all of the html files for the site we are integrating into our custom Wordpress portfolio theme. If you open the work.html file in a text editor like Sublime Text 2, you will see the content that you can then copy and paste into the appropriate fields within the admin area.

Time to tag in the expert Zack Gordon I think and ask him where we can find the content for the 'testimonials' and 'work' for this project.

Thank you for your continued help is most certainly is appreciated. Is there any way that you could email me your finished of that page? Because I am still a bit confused as to what content needs to go where.

Hi David, here is my code which is working just fine:

    <?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><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    <?php the_field( 'description' ); ?>
    <hr>

<?php endwhile; else: ?>

    <p>The are no post or pages</p>


<?php endif; ?>

<?php get_footer(); ?>

Okay I copy the code that you have posted here but I am still running into the same problem. Is there something that I need to do in WordPress administration?

Yes the titles and descriptions need to be added from with the Wordpress admin area. If you have set up your custom fields for 'work' via the plugin then you should see the 'Work' option under 'Comments' on the left-hand-side menu.You need to go to Work - Add Project and add a new one for each. Maybe just add a couple and test. You will be required to add the title, description and button colour for the project to be able to then publish.

Let me know how you get on.

Thank you again for your continued help. I went ahead and created a new project and the first title is displayed with the description is not. The descriptive information is within the description field and again I have copied and pasted your code I'm not sure as to what is going on.

Well if the title is now displaying for one of the work projects you have just posted it must be something in the code of your work.php file :-/.

I am confused I have copied and pasted your code.

Did you label your description field correct when you added it via the plugin within the Wordpress admin? Check that it is spelt exactly the same as in your work.php file.

My apologies for the late reply. I have been out of town "holidays" I believe I named correctly but I will have to double check.

No problem :)

If you are still having problems you can send me your files. I will have a check and see if I can find what is going wrong.