In this article I show how a random Google Adsense ad (or just any HTML) can be inserted in between every two Posts on Posts page (Blog) and category archives when using Genesis.
Step 1
Install and activate Ads by datafeedr.com plugin. This plugin allows us to add advertisements (any HTML code) and provides shortcode and function call to display the ads. Ads can be grouped and for each ad, Start Date and End Date can be set as also a limit on number of impressions.
To view the full content, please sign up for the membership.
Already a member? Log in below or here.
Is there a way to show [shortcode] in between every 2 posts?
Love it.
Same method as Sridhar mentioned and replace line 26 with echo do_shortcode( ‘[shortcode]’ );
Ref – http://codex.wordpress.org/Function_Reference/do_shortcode
Sorry so long to get back to ya, I tried the shortcode fix but it results in kiling site till i replace it with Srihars’
code. ( i copy pasted exactly)
any idea why?
Hello. Is there a way to show content (ad, image, shorcode etc) in between for example the 2nd and third post, and then in between the 4th and 5th (but then NOT in between any other posts in that page?
Thanks,
Chris
Hi Chris,
The code in this tutorial is for inserting ads between 2nd and 3rd, 4th and 5th posts and so on. Isn’t that what you are asking?
Not quite – I would be interested in how to then STOP any repeated insertion of content after the 4th & 5th – so there are only 2 ads in the flow of all the posts, even when the user has clicked through to subsequent paginated pages…
Ok, understood now.
Try this: http://pastebin.com/raw/fdJxrN2B
Thanks Sridhar,
I ended up using this:-
add_action( ‘genesis_after_entry’, ‘fd_category_clients’ );
function fd_category_clients() {
if ( is_paged() ) {
return;
}
global $wp_query;
if( ($wp_query->current_post) == 1 ) {
// added content here
}
elseif( ($wp_query->current_post) == 3 ) {
// added content here
}
}
In conditional hook box using Dynamik… works a treat.
Thanks loads for your code too – it’s great to see that the idea is the same so re-inforces what I’m doing is correct and I needed the
if ( is_paged() )
{
return;
}
part so thanks for that 🙂
Chris