I would like to add a specific category of post (such as 'Sponsors') after every 3rd post. Example:
Post Post Post Sponsor Post Post Post Sponsor Post Post Post Sponsor
I found this code which is used to inject Adsense between posts in the loop, but is it possible to use this code to add a specific post category between posts in the loop? How would I alter this code to achieve this? Or is there a better method?
Code to inject Adsense between posts:
Add your custom function or introduce your own hook inside the loop:
<article id="entry-<?php the_ID(); ?>" <?php post_class('entry group'); ?>>
<div id="postcontent"></div>
</article>
<?php do_action( 'inject_ads', $wp_query->current_post ); ?>
where you can inject your ads like this:
add_action( 'inject_ads', function( $i ){
if( 4 === $i % 5 )
{
echo '... your ad code ...';
}
});
code found here:
http://stackoverflow.com/questions/22795309/how-to-add-looping-advertisement-and-different-post-stlyes-inside-wp-loop