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

"no" on display_on_homepage not working.

I followed Janet Chan's post on activating how to suppress the posting of an individual page in flex-slider. No luck.

Adding this line that was supposed to fix the problem doesn't do a thing:

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

    <ul class="slides">
    <?php 
        $args = array(
            'post_type' => 'image_slider'
        );
        $slideshow_query = new WP_Query( $args );
    ?>          
    <?php if ( have_posts() ) : while ( $slideshow_query->have_posts() ) : $slideshow_query->the_post(); ?>


<?php $display = get_field('image_slider_image'); if ( $display[0] == 'yes' ); ?>

        <li class="flex_active_slide">
            <div class="container">
                <a href="<?php the_permalink(); ?>"><img src="<?php the_field('image_slider_image'); ?>"></a>
        </div>

        </li>





    <?php endwhile; endif; ?>

    </ul>


</div>

How do I fix this?

5 Answers

Kevin Korte
Kevin Korte
28,148 Points

First things first, make sure the slug for your custom field is exactly "image_slider_image".

It is exactly that.

Kevin Korte
Kevin Korte
28,148 Points

Are you getting any content or just a blank white page? Is your html showing up?

Thanks, Kevin, for your promptness.

Yes, my content is showing like it should. The slider works perfectly.

The problem is in my ACF setup. I have designated a "yes" field button in my Image_slider group field set to show an image when selected. The page seems to ignore the following code:

<?php $display = get_field('image_slider_image'); if ( $display[0] == 'yes' ); ?>

This is the line Zac Gordon recommended in another post.

My goal is to feature just a few products out of hundreds of products to showcase on the front page. I want the default to be "no", don't show as feature. But to load in the general catalog.

The tutorial that Zac presented showed him setting up that feature. But, I read in ther posts that others were not able to get that feature to work. I followed everything to no avail.

I finally got it to work. Not sure exactly what I got right/changed. It's there in the code somewhere.

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

    <ul class="slides">
    <?php 
        $args = array(
            'post_type' => 'products'
        );
        $slideshow_query = new WP_Query( $args );
    ?>          


 <?php if ( have_posts() ) : while ( $slideshow_query->have_posts() ) : $slideshow_query->the_post(); ?>
       <?php $display = get_field('display_on_homepage'); if ($display[0] == 'yes' ): ?>


        <li class="flex_active_slide">
            <div class="container">

                <a href="<?php the_permalink(); ?>"><img src="<?php the_field( 'homepage_slider_image' ); ?>"></a>

        </div>

        </li>

        <?php endif; ?>


    <?php endwhile; ?>


    <?php endif; ?>

    </ul>


</div>
Christie Parkhurst
Christie Parkhurst
6,059 Points

Thanks for posting this! I was having the same problem, and it was fixed by your code. The difference seems to be using a lower case "y" in the yes.