您可以以此作为开始。这需要进入功能。php。您可以在模板文件中使用普通循环,无需更改任何内容。这将在帖子3和6之后添加类别中的帖子。只需记住使用slug 属于您的类别。
function category_after_third_post( $post ) {
global $wp_query;
if ( $wp_query->post != $post )
return;
if ( 3 != $wp_query->current_post || 6 != $wp_query->current_post )
return;
$args = array(
\'category_name\' => \'uit-die-koskas\',
\'posts_per_page\' => 1
);
$catquery = new WP_Query($args);
if ( $catquery->have_posts() ) :
while ( $catquery->have_posts() ) : $catquery->the_post();
get_template_part( \'content\', get_post_format() );
endwhile;
endif;
}
add_action( \'the_post\', \'category_after_third_post\' );
或者,您可以创建一个小部件,并在每第三篇文章之后添加它。
function cat_posts_sidebar() {
register_sidebar( array(
\'name\' => __( \'Sidebar for ads\', \'my-theme\' ),
\'id\' => \'sidebar-10\',
\'description\' => __( \'Sidebar to display cat post\', \'my-theme\' ),
\'before_widget\' => \'<aside id="%1$s" class="widget %2$s">\',
\'after_widget\' => \'</aside>\',
\'before_title\' => \'<h3 class="widget-title">\',
\'after_title\' => \'</h3>\',
) );
}
add_action( \'widgets_init\', \'cat_posts_sidebar\' );
然后将第一个函数修改为此。
function category_after_third_post( $post ) {
global $wp_query;
if ( $wp_query->post != $post )
return;
if ( 3 != $wp_query->current_post || 6 != $wp_query->current_post )
return;
echo \'<div class="after-post-widget widget-area">\';
dynamic_sidebar( \'sidebar-10\' );
echo \'</div><!-- end .after-post-widget -->\';
}
add_action( \'the_post\', \'category_after_third_post\' );