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 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'
            );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流