我想知道是否有一种方法可以在我的自定义帖子循环中将内容块插入到特定的帖子编号之后。
从本质上讲,我想说:
在最近的两个最新代码之后,插入以下代码块。
如果可以做到这一点,我也很有兴趣知道这样的事情是否可以实现:
启动一个排除特定Post格式(或类别)的自定义Post循环,但在每2个Post之后,插入1个排除的Post格式。
谢谢你的帮助。
<!-- #STICKY-POSTS |begin| -->
<section id="sticky-posts">
<?php
$args = array( 'post_type' => 'portfolio', 'posts_per_page' => 2, 'cat' => '8' );
$custom_query = new WP_Query( $args);
while($custom_query->have_posts()) : $custom_query->the_post();
get_template_part('format', 'standard');
endwhile;
?>发布于 2012-06-29 00:03:34
这样做:
<!-- #STICKY-POSTS |begin| -->
<section id="sticky-posts">
<?php
$args = array( 'post_type' => 'portfolio', 'posts_per_page' => 2, 'cat' => '8' );
$custom_query = new WP_Query( $args);
$x = 0;
while($custom_query->have_posts()) : $custom_query->the_post();
if($x==2) {
display your thing here.
$x=0;
}
get_template_part('format', 'standard');
$x++
endwhile;
?>除非我搞砸了什么,否则x=0会在第一次正常post时变成1,在第二次正常post时变成2,然后在if语句中返回true,回到0并重复漂洗。
https://stackoverflow.com/questions/11237613
复制相似问题