我正在制作一本在线杂志。现在我正在尝试显示我正在发布的帖子。我已经设法做到了这一点,但我想要的是,如果帖子被归类为“街头风格”,则循环将与归类为“摄影”的帖子完全不同。我已经设法对一个类别执行此操作,我如何才能对其他类别执行相同的操作,并以另一种方式设置样式?我尝试使用与 <?php if (is_category( 'Streetstyle' ) || in_category( 'Streetstyle' ) ) { ?>
相同的代码,但随后主题被窃听并且帖子出现两次。你知道更好的方法吗?
这是我的代码:
<?php query_posts('posts_per_page=9' . '&orderby=date');
while ( have_posts() ) : the_post(); ?>
<?php if (is_category( 'Streetstyle' ) || in_category( 'Streetstyle' ) ) { ?>
<div <?php post_class('pin streetstyle'); ?>>
<a href="<?php the_permalink(); ?>">
<div class="heading">
<h1>Fashion</h1>
</div>
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
<div class="heading">
<h1><?php the_title(); ?></h1>
</div>
</a>
</div>
<?php } else { ?>
<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 <br><br>'); ?>
</div>
<?php } ?>
<?php endwhile;
// Reset Query
wp_reset_query(); ?>
最佳答案
如果您有很多类别,我建议您使用 switch,它会节省您的时间并且您的代码看起来会更清晰。
关于php - Wordpress:使用不同的循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12354114/