Wordpress,如何制作一个;如果属于类别,则;在一个循环中?
如何使这个条件在循环中工作?这似乎很容易,但它不起作用 有关部分:Wordpress,如何制作一个;如果属于类别,则;在一个循环中?,wordpress,Wordpress,如何使这个条件在循环中工作?这似乎很容易,但它不起作用 有关部分: <?php if (is_category('Sup-FAQ')) : ?> <p>If in cat sup-faq</p> <?php else : ?> <p>If not then print this</p> <?php endif; ?> 如果在cat
<?php if (is_category('Sup-FAQ')) : ?>
<p>If in cat sup-faq</p>
<?php else : ?>
<p>If not then print this</p>
<?php endif; ?>
如果在cat sup常见问题解答中
如果没有,那么打印这个
整个循环:
<?php
$cats = get_categories();
foreach ($cats as $cat) {
$args = array(
'post_type' => 'support_post',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => $cat->cat_ID,
),
),
);
$query = new WP_Query($args);
if ( $query->have_posts() ): ?>
<h4><?php echo $cat->cat_name ; ?></h4>
<?php if (is_category('Sup-FAQ')) : ?>
<p>If in cat sup-faq</p>
<?php else : ?>
<p>If not then print this</p>
<?php endif; ?>
<ul>
<?php
while($query -> have_posts()) : $query -> the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php
wp_reset_query() ;
}
?>
如果在cat sup常见问题解答中
如果没有,那么打印这个
循环获取自定义帖子类型“support post”中的所有帖子,并按类别列出它们。现在我需要一个循环中的条件,如果满足类别,它将显示一些文本。提前感谢。发件人:若要测试帖子是否属于某个类别,请使用in_category()
另一方面,在你的例子中,你已经在你的外循环中得到了类别。只需检查$cat->name
:
<?php if ($cat->name == 'Sup-FAQ'): ?>
你比我快了3.2秒=)谢谢,成功了!除了这个,我一定试过了所有的选择:)