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

Custom post type: display_on_homepage still not working

Although i have read previous posts on the same issue of the display_on_homepage not working and added the code below,

<?php $display = get_field('display_on_homepage'); if ( $display[0] == 'Yes' ): ?>

it breaks my homepage. Please help

Here is my code

<div id="featured" class="clearfix flexslider">

    <ul class="slides">

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

        <?php $display = get_field('display_on_homepage'); if ( $display[0] == 'Yes' ): ?>

            <li style="background-color: <?php the_field('background_color'); ?>";>
                <div class="container">
                    <div class="grid_8">
                        <img src="<?php the_field('homepage_slider_image'); ?>" alt="<?php the_title(); ?> Project Screenshot">
                    </div>
                    <div id="featured-info" class="grid_4 omega">
                        <h5>Featured Projects</h5>
                        <h3 style="color: <?php the_field('button_color'); ?>"><?php the_title(); ?></h3>
                        <p><?php the_field('description'); ?></p>
                        <a class="btn blue" style="background-color: <?php the_field('button_color'); ?>" href="<?php the_permalink(); ?>">View Project &rarr;</a>
                    </div>
                </div>
            </li>

        <?php endwhile; endif; ?>

    </ul>


</div>

2 Answers

Matt Campbell
Matt Campbell
9,767 Points

Have you got a link to the page? How is it breaking?

It's now working. There was an additional semi-colon in my code. Thanks for the concern.