【发布时间】:2016-03-02 16:15:57
【问题描述】:
我正在通过自定义帖子类型和类别获取数据。我添加了 12 个类别一月到十二月,一月有 1 个帖子,二月有 2 个帖子
我在 1 月帖子上努力做的事情 2 圆圈显示在左侧
请问如何检查类别?
这里是网站http://novartis.portlandvault.com/timeline/
谢谢
<div id="timeline">
<?php
//Define your custom post type name in the arguments
$args = array('post_type' => 'timeline', 'order' => 'asc' );
//Define the loop based on arguments
$loop = new WP_Query( $args );
//Display the contents
while ( $loop->have_posts() ) : $loop->the_post();
$thumb = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'large') );
$category = get_the_terms($id, 'timeline_categories');
?>
<div class="timeline-item">
<div class="timeline-icon">
<div class="timeline-month">
<?php echo $category[0]->name;?>
</div>
</div>
<div class="timeline-content right">
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php echo the_content(); ?>
</p>
<div class="timeline_img">
<img src="<?php echo $thumb; ?>" class="img-responsive">
</div>
</div>
</div>
<?php endwhile;?>
</div>
<!-- Timeline ends here -->
【问题讨论】:
-
感谢安德烈斯的回复。如果我在三月发布一月的帖子怎么办?有没有办法存储类别,而不是检查帖子是否与不显示时间线图标相同的类别,否则如果类别是新的而不是显示时间线图标?这有意义吗?