繁体   English   中英

特殊类别帖子的不同循环

[英]Different loop for posts in a special category

我正在使用Wordpress,并且想对“ 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(); ?>

在此进行实时预览。

在您的问题中,您谈论的是使用不同的循环,但是我正在根据您所说的内容以及它实际上与您使用的相同循环的链接进行思考,您只需添加一些条件代码来检查帖子是否为在Streetstyle类别中。

下面的代码做到了这一点,它检查帖子是否为in_category()并且我还添加了is_category() ,如果要显示类别存档,可以使用该代码。

is_category

in_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(); ?>

我猜你的意思是在存档页面中-在这种情况下,请使用is_category() ;

所以,

if(is_category('Streetstyle')) :
  // Add black border style and content
else :
  // Do other cool stuff
endif;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM