如何在Wordpress 4.0的索引或类别的第三篇文章后添加包含内容的横幅或DIV?
// Start the Loop.
while ( have_posts() ) : the_post();
/*
* Include the post format-specific template for the content. If you want to
* use this in a child theme, then include a file called called content-___.php
* (where ___ is the post format) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
endwhile;
// Previous/next page navigation.
twentyfourteen_paging_nav();
else :
// If no content, include the "No posts found" template.
get_template_part( 'content', 'none' );
endif;
?>
答案 0 :(得分:2)
您还可以使用WP_Query中填充的内置current_post属性,使其看起来像:
// Start the Loop.
while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
//count starts at 0
if( $current_post == 2 ) :
echo '<div class="banner"><img src="your_banner_url" /></div>';
endif;
endwhile;
答案 1 :(得分:0)
$counter = 1;
// Start the Loop.
while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
if( $counter == 3 )
echo '<div class="banner"><img src="your_banner_url" /></div>';
$counter++;
endwhile;