下面的代码用于在wordpress存档页面上的第5个帖子之后注入广告横幅,我想在第1和第5个帖子之后注入横幅,但我不知道如何修改代码以满足我的需要。
<?php
function insert_between_posts( $post ) {
global $wp_query;
// Check if we're in the main loop
if ( $wp_query->post != $post )
return;
// Check if we're at the right position
if ( 5 != $wp_query->current_post )
return;
// Display the banner
echo '
<div banner>BANNER</div>
';
}
add_action( 'the_post', 'insert_between_posts' );
?>
你试着改变吗?
if ( 5 != $wp_query->current_post )
同
if ( 5 % $wp_query->current_post == 0 || 1 != $wp_query->current_post)
每当“current_post”是5的倍数或者等于1时,我的代码就会显示横幅