Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

General Discussion

How to Build a WordPress Theme, featured project

So in the "How to Build a WordPress Theme" on the home page there is a slider to show featured work, it however simply displays all work (one at a time.. or one per slide).

In this tutorial we added a custom field of "display_on_the_homepage", but we never used it. No matter if this check-box is ticked or not projects still show up in the slider. As do their images.

I've looked at the arguments array and I some how need to implement 'the_field('display_on_the_homepage')' => true, or something of the likes but I can't get it to work.

http://teamtreehouse.com/library/how-to-build-a-wordpress-theme/extending-wordpress-template-functionality/finishing-the-homepage-template-2

2 Answers

Not too sure of the context, but in order to have a feature like this work, your display code will need to read the filter as well. You need some kind of conditional that is something along the lines of:

<?php 
    if($item->display_on_the_homepage == true){
        add_item_to_show_array($item);
    }
?>

That's the logic I would use to create a conditional that filters what is added to the slider, but again, I am not entirely sure if this fits the exact context that you are inquiring about?

(This conditional could also be placed in the actual loop code)

<?php 
   foreach($something as $something_else){
        if($something_else->display_on_the_homepage == true){
           // Show image on slider
        } else {
            // display_on_the_homepage was false, handle a false value here.
        }
   }
?>

thanks I'll be looking to that mate, bout to shoot you an email with a link btw.