我用的是212,我需要在帖子之间插入一个div。我不知道如何停止循环,插入div,然后重新启动循环。
有人能解释一下吗?谢谢
我用的是212,我需要在帖子之间插入一个div。我不知道如何停止循环,插入div,然后重新启动循环。
有人能解释一下吗?谢谢
您可以使用current_post
风险值$wp_query
对象,并在特定位置或某个间隔插入标记。一个简单的例子:
while( have_posts() ):
the_post();
the_title();
the_excerpt();
// if current_post is 1, insert the div
// note that current_post starts at 0,
// so this will be after the second post\'s content
if( 1 == $wp_query->current_post ):
echo \'<div>My div!</div>\';
endif;
endwhile;
您可以添加<div>
在通过修改索引输出帖子之后。主题的php。看看第22-25行(http://themes.trac.wordpress.org/browser/twenty-twelve/0.9/index.php), 您可以将其放置在第24行之后,该行负责拉入并显示正确的内容类型模板。
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( \'content\', get_post_format() ); ?>
<!-- You could insert your div here -->
<?php endwhile; ?>
如果你想挑三拣四它后面是哪种类型的帖子(普通帖子、图片帖子等),那么你可以编辑内容-*。php文件本身,并将其放在这些模板的末尾。单独查询这两个字段中的任何一个都会得到预期的结果(显示帖子)。但是,当这两个字段都包含在查询中时(例如下面的示例中显示的“foo”和“bar”),则不会显示帖子。function do_stuff( ) { global $wpdb; return \" AND ($wpdb->postmeta.meta_key = \'foo\' AND $wpdb->postmeta.meta_value = \'1\')