You can use this as a start. This need to go into functions.php. You can use your normal loop in your template files, no need to change anything there. This will add a post from a category after post 3 and 6. Just remember to change the category name with the slug of your category.
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' );
Alternatively, you can create a widget and add that after every 3rd 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' );
Then modify the first function to this.
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' );