具有不同引导列的Wordpress循环 [英] Wordpress loop with different bootstrap columns

查看:45
本文介绍了具有不同引导列的Wordpress循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个wordpress循环,其中第一篇文章将为col-md-12,接下来的四篇文章将为col-md-6

 < div class ="col-md-12"></div>

</div>< div class ="col-md-6"></div>< div class ="col-md-6"></div>< div class ="col-md-6"></div>

然后

 < div class ="col-md-12"></div>< div class ="col-md-6"></div>< div class ="col-md-6"></div>< div class ="col-md-6"></div>< div class ="col-md-6"></div> 

解决方案

也许这会有所帮助:

 <?php如果(have_posts()){$ counter = 0;while(have_posts()){if(($ counter%5)== 0){?>< div class ="col-md-12">调用当前帖子的循环标签以显示所需的数据</div><?php}其他{?>< div class ="col-md-6">调用当前帖子的循环标签以显示所需的数据</div><?php}$ counter ++;}//结束片刻}//万一?> 

如果仅将帖子限制为10个:

 <?php$ wp =新的WP_Query(array('posts_per_page'=> 10));如果($ wp-> have_posts()){$ counter = 0;while($ wp-> have_posts()){if(($ counter%5)== 0){?>< div class ="col-md-12">调用当前帖子的循环标签以显示所需的数据</div><?php}其他{?>< div class ="col-md-6">调用当前帖子的循环标签以显示所需的数据</div><?php}$ counter ++;}//结束时}//万一?> 

您必须调用所有标签,例如:the_title(),the_content()在$ wp之前,但不是义务

i need to create a wordpress loop where the first post will be col-md-12 and the next 4 posts will be col-md-6

<div class= "col-md-12">
</div>
<div class= "col-md-6">
</div>
<div class= "col-md-6">
</div>
<div class= "col-md-6">
</div>
<div class= "col-md-6">
</div>

and then

<div class= "col-md-12">
</div>
<div class= "col-md-6">
</div>
<div class= "col-md-6">
</div>
<div class= "col-md-6">
</div>
<div class= "col-md-6">
</div>

解决方案

may be this can help :

<?php 
if ( have_posts() ) {
     $counter = 0;
    while ( have_posts() ) {

    if(($counter%5) == 0 ){?>
        <div class= "col-md-12"> call the loop tags of the curent post to show data that you want </div>
<?php
}
    else{?>

     <div class= "col-md-6"> call the loop tags of the curent post to show data that you want </div>

    <?php }

    $counter++;
    } // end while
} // end if
?>

In case to limit post to 10 post only:

   <?php 
    $wp =  new WP_Query(array('posts_per_page'=>10));
    if ( $wp->have_posts() ) {
         $counter = 0;
        while ( $wp->have_posts() ) {

        if(($counter%5) == 0 ){?>
            <div class= "col-md-12"> call the loop tags of the curent post to show data that you want </div>
    <?php
    }
        else{?>

         <div class= "col-md-6"> call the loop tags of the curent post to show data that you want </div>

        <?php }

        $counter++;
        } // end while
    } // end if
    ?>

you have to call all the tags like : the_title(), the_content() preceded by $wp , but not obligation

这篇关于具有不同引导列的Wordpress循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆