在第三个帖子后添加横幅

时间:2015-04-11 作者:Rafael

如何在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;
        ?>

1 个回复
SO网友:Mayeenul Islam

这与WordPress完全没有关系,这是一个通用的PHP问题,因此这里没有话题。很简单,按照内联注释进行操作,您就可以获得它了。:)

<?php
//declare a counter
$counter = 1;

// 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() );

//check the counter and display your content
if( $counter === 3 ) { ?>
    <div class="third-div-in-loop">content</div>
<?php }

//update the counter on every loop
$counter++;

endwhile;

结束

相关推荐

使用新的WP-Query()从循环中过滤后期格式;

嗨,我目前正在为我的博客构建一个主题。下面的代码指向最新的帖子(特色帖子)。因为这将有一个不同的风格比所有其他职位。然而我想过滤掉帖子格式:链接使用我在循环中定义的WP查询,因为它给我带来了更多的灵活性。我该怎么做呢? <?php $featured = new WP_Query(); $featured->query(\'showposts=1\'); ?> <?php while ($featured->have_post