如果是类别,则回显自定义字段

时间:2014-12-05 作者:nobot-z

在bog标准单曲上。php文件如果post category=“Events”或category ID“4”,我如何回应以下内容。我要回应的代码是:

        <div class="event-post-icons">
            <ul>
                <li class="single-post-date"><?php the_field(\'event_date\'); ?></li>
                <li class="single-post-time"><?php the_field(\'event_time\'); ?></li>
                <li class="single-post-price"><?php the_field(\'booking_fee\'); ?></li>
                <li class="single-post-palce"><?php the_field(\'event_location\'); ?></li>
            </ul>
        </div><!-- /event-post-icons -->
谢谢

1 个回复
SO网友:NateWr

使用in_category() 函数,如下所示:

<?php if ( in_category( 4 ) ) : ?>
    <div class="event-post-icons">
        <ul>
            <li class="single-post-date"><?php the_field(\'event_date\'); ?></li>
            <li class="single-post-time"><?php the_field(\'event_time\'); ?></li>
            <li class="single-post-price"><?php the_field(\'booking_fee\'); ?></li>
            <li class="single-post-palce"><?php the_field(\'event_location\'); ?></li>
        </ul>
    </div><!-- /event-post-icons -->
<?php endif; ?>
如果要使用此选项在循环外测试帖子,则需要添加帖子id:

<?php if ( in_category( 4, $post_id ) ) : ?>

结束

相关推荐