dsgsgs30201
2013-08-05 00:53 阅读 37
已采纳

Wordpress ACF复选框拉

So I did my due diligence looking on here for an answer since this has come up a few times in the Treehouse forum, but found nothing related. I also tried to find a related topic on the acf site but that didn't give me the right info either. Hopefully you guys can help me out.

At the end of a tutorial on Treehouse, the instructions explain to add a few custom fields using ACF. He explains how to pull all of those in the code except on one crucial one.

We are supposed to create a checkbox field with the Field Label as Display on Homepage Slider and Field Name (or slug) as display_on_homepage. The idea is that we check this on each custom post entry that we want to display on the homepage slider, if you hadn't already guessed that.

Here's the code for the slider as it stands now.

<?php get_header('header.php'); ?>
</div>
    <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(); ?>
            <li style="background-color:<?php the_field( 'background_color' ); ?>;">
                <div class="container">
                    <div class="grid_7">
                        <img src="<?php the_field( 'homepage_slider_image' ); ?>" alt="<?php the_title(); ?> Project Screenshot">
                    </div>
                    <div id="featured-info" class="grid_5 omega">
                        <h6>Featured Work</h6>
                        <h3><?php the_title(); ?></h3>
                        <p><?php the_field( 'description' ); ?></p>
                        <p><a class="btn blue" style="background-color: <?php the_field( 'button_color' ); ?>" href="<?php the_permalink(); ?>">View Project &rarr;</a></p>
                    </div>
                </div>
            </li>
        <?php endwhile; endif; ?>
        </ul>
    </div>

I'm sure I need to pull some conditions in the args or even establish a different rule in my acf plugin, but I'm at a loss as to where to start with that can of worms. Thanks in advance for any help or advice. I'll be sure to forward this answer to the forum if I can get any assistance.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    drz73366 drz73366 2013-08-05 01:18

    You'll want to add in an argument to your query for your custom field (meta field): http://codex.wordpress.org/Class_Reference/WP_Query

     $args = array(
                'post_type' => 'work',
                'meta_key' =>'display_on_homepage',
                'meta_value'=>'true'
            );
    
    点赞 评论 复制链接分享
  • douda5227 douda5227 2013-08-05 01:40

    The first answer is almost there, just missing a couple of commas :)

    $args = array(
            'post_type' => 'work',
            'meta_key' =>'display_on_homepage',
            'meta_value'=>'true'
        );
    
    点赞 评论 复制链接分享

相关推荐