问题描述
我正在基于Twitter Bootstrap构建一个Wordpress主题.借助Bootstrap的自适应布局, .row-fluid
跨越了100%的页面,并且一行中可以包含12个"span".
<?php query_posts('category_name = feature-articles& showposts = 6');?><?php while(have_posts()):the_post();?>< div class ="span4">< div class ="main-thumb"><?php echo get_the_post_thumbnail(($ page-> ID),'main-thumb');&& lt;/div>< a href =<?php the_permalink();?>">< h3 class ="title"><?php the_title();η/h 3</a><p class="摘录"><?php$ my_excerpt = get_the_excerpt();如果($ my_excerpt!=''){//执行了一些字符串操作}echo $ my_excerpt;//将处理后的值输出到页面&& lt;/p><?php endwhile;&& lt;/div> 这将创建6个"span4",我想跨2个不同的行-但是由于循环,无法关闭原始的 .row-fluid
div并在3之后打开另一个帖子已创建.
为简单起见,我想获取帖子1、2和3,然后关闭 .row-fluid
div并创建另一个,然后获取帖子4、5和6.一点循环操作?
解决方案您必须在循环中放置一个计数器,当计数器达到3时,添加一个close/open标签.我还为循环的开头添加了 if(have_posts())
,以避免发生错误(如果没有帖子,还可以输出一条消息).
< div class ="row-fluid"><?php $ i = 0?><?php query_posts('category_name = feature-articles& showposts = 6');?><?php if(have_posts()):while(have_posts()):the_post();?><?php if($ i == 3):?></div>< div class ="row-fluid"><?php endif;?>< div class ="span4">< div class ="main-thumb"><?php echo get_the_post_thumbnail(($ page-> ID),'main-thumb');?></div>< a href =<?php the_permalink();?>">< h3 class ="title"><?php the_title();&& lt;/h3></a>< p class ="excerpt"><?php$ my_excerpt = get_the_excerpt();如果($ my_excerpt!=''){//执行了一些字符串操作}echo $ my_excerpt;//将处理后的值输出到页面?></p><?php $i++ ?><?php endwhile;?><?php endif;?></div>
I'm building a Wordpress theme based around Twitter Bootstrap. With Bootstrap's responsive layout .row-fluid
spans 100% of the page and can have 12 'spans' within one row.
<div class="row-fluid">
<?php query_posts('category_name=feature-articles&showposts=6'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="span4">
<div class="main-thumb"><?php echo get_the_post_thumbnail(($page->ID) , 'main-thumb'); ?></div>
<a href="<?php the_permalink(); ?>"><h3 class="title"><?php the_title(); ?></h3></a>
<p class="excerpt"><?php
$my_excerpt = get_the_excerpt();
if ( $my_excerpt != '' ) {
// Some string manipulation performed
}
echo $my_excerpt; // Outputs the processed value to the page
?></p>
<?php endwhile; ?></div>
This creates 6 "span4", which I want to span across 2 different rows - but because of the loop, there's no way to close the original .row-fluid
div and open another after 3 posts have been created.
For simplicity's sake, I want to get posts 1, 2 and 3, then close the .row-fluid
div and create another, then get posts 4, 5 and 6. Is this possible with a bit of loop manipulation?
解决方案 You'd have to put a counter in the loop, and when it reaches 3, add a close/open tag. I've also added if(have_posts())
to the start of your loop, to avoid errors (also allows you to output a message if there are no posts).
<div class="row-fluid">
<?php $i = 0 ?>
<?php query_posts('category_name=feature-articles&showposts=6'); ?>
<?php if(have_posts()) : while (have_posts()) : the_post(); ?>
<?php if( $i == 3 ) : ?>
</div>
<div class="row-fluid">
<?php endif; ?>
<div class="span4">
<div class="main-thumb">
<?php echo get_the_post_thumbnail(($page->ID) , 'main-thumb'); ?>
</div>
<a href="<?php the_permalink(); ?>">
<h3 class="title"><?php the_title(); ?></h3>
</a>
<p class="excerpt">
<?php
$my_excerpt = get_the_excerpt();
if ( $my_excerpt != '' ) {
// Some string manipulation performed
}
echo $my_excerpt; // Outputs the processed value to the page
?>
</p>
<?php $i++ ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
这篇关于中断wordpress循环,然后在插入div后重新进入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-22 15:07