【发布时间】:2018-04-18 20:10:56
【问题描述】:
我正在尝试为我的骨骼主题 wordpress 网站创建一个模板,该网站具有以下网格。
我似乎无法弄清楚如何从数据库中调用我的所有帖子并使用多个循环输出它们,这些循环带有我用骨骼 CSS 设置的不同模板
示例查询:
<?php $args = array(
'post_type' => array ( 'post' ),
'post_count' => 4
);
$query = new WP_query ( $args );
if ( $query->have_posts() ) {
$count = 0;
}
?>
<section class="blog-posts grid">
<?php while ( $query->have_posts() ) : $query->the_post();
if ( get_post_type() == 'post' && $count == 0 ) {
include( locate_template( 'includes/homepage-1of2.php' ));
$count++;
}
endwhile; ?>
</section>
然后在第二次运行时增加计数。所发生的只是显示同一个帖子(共 12 个)。
提前感谢您的帮助
编辑:
使用来自 mtr.web 的代码
我现在有了这个
<?php while ( $query->have_posts() ) : $query->the_post();
if ( get_post_type() == 'post') {
switch($count) {
case 0:
include( locate_template( 'includes/homepage-1of1.php' ));
break;
case 1:
include( locate_template( 'includes/homepage-1of2.php' ));
break;
case 2:
include( locate_template( 'includes/homepage-1of2.php' ));
break;
case 3:
include( locate_template( 'includes/homepage-1of3.php' ));
break;
case 4:
include( locate_template( 'includes/homepage-1of3.php' ));
break;
case 5:
include( locate_template( 'includes/homepage-1of3.php' ));
break;
default:
include( locate_template( 'includes/homepage-1of1.php' ));
}
$count++;
}
endwhile; ?>
这很棒并且很简短,但我现在需要为我的所有帖子有效地运行这个循环,所以一次又一次地复制这 6 个帖子结构 - 有没有办法告诉循环运行那些模板定位器?
【问题讨论】: