我正在使用Wordpress,我想对“Streetstyle”类别中的帖子使用不同的循环。因此,例如,如果在“摄影”中分类的帖子,循环的样式将是正常的。但如果帖子被归类为“Streetstyle”,帖子周围会有黑色边框。
这是我的循环:
<?php query_posts('posts_per_page=9' . '&orderby=date');
while ( have_posts() ) : the_post(); ?>
<div <?php post_class('pin'); ?>>
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
the_content('Les mer'); ?>
</div>
<?php endwhile;
// Reset Query
wp_reset_query(); ?>
答案 0 :(得分:1)
在你的问题中,你谈到使用一个不同的循环,但我正在考虑你所说的和它实际上是你使用的相同循环的链接,你只需添加一些条件代码来检查是否该帖子属于Streetstyle类别。
以下代码执行此操作,它会检查帖子是否为in_category()
,并且我还添加了is_category()
,如果您要显示类别存档,则会使用{}
班级名称已适当更改。
<?php query_posts('posts_per_page=9' . '&orderby=date');
while ( have_posts() ) : the_post();
if (is_category( 'Streetstyle' ) || in_category( 'Streetstyle' ) ) ?>
<div <?php post_class('pin'); ?>>
<?php } else { ?>
<div <?php post_class('pin-blackborder'); ?>>
<?php } ?>
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
the_content('Les mer'); ?>
</div>
<?php endwhile;
// Reset Query
wp_reset_query(); ?>
答案 1 :(得分:0)
我猜您的意思是在存档页面中 - 在这种情况下,使用is_category();
所以,
if(is_category('Streetstyle')) :
// Add black border style and content
else :
// Do other cool stuff
endif;