How to add adsense ad after 5 & 10 articles on main page

Posted in: Newspaper
Post count: 21

I have set grid style articles and i want to show adsense ad after 5th article & 10th article, where can i add code for that?

Thanks

Post count: 7909

Hi,

Please add this code in loop.php file to have ads on homepage article list: http://screencast.com/t/rG7rDLmRrTD

$adcounter++;
if (is_home()) {
if ($adcounter == 5 or $adcounter == 10) {
echo do_shortcode('[td_ad_box spot_id="custom_ad_1"]');
}
}

Please also paste the ad code in custom ad 1 or change the number of custom ad in the code(the custom ad that you want to show): http://screencast.com/t/n6omBeV0r

Hope this helps!

Post count: 4

Once Again, thanks! I’ve made some adjustments on this code, but it did work!

Thanks!

Post count: 135

I have this issue

instead of appearing the ads, it appears the code between the posts

Like this

[td_ad_box spot_id=”custom_ad_2″]

Check http://www.rnbjunk.com

Post count: 135

$td_module = td_api_module::get_by_id($td_module_class);
if ($td_module[‘uses_columns’] === false) {
$td_template_layout->disable_output();
}

if (have_posts()) {
while ( have_posts() ) : the_post();
echo $td_template_layout->layout_open_element();

if (class_exists($td_module_class)) {
$td_mod = new $td_module_class($post);
echo $td_mod->render();
} else {
td_util::error(__FILE__, ‘Missing module: ‘ . $td_module_class);
}

echo $td_template_layout->layout_close_element();
$td_template_layout->layout_next();

$adcounter++;
if (is_home()) {
if ($adcounter == 4 or $adcounter == 8) {
echo do_shortcode(‘[td_ad_box spot_id=”custom_ad_2″]’);
}
}

endwhile; //end loop
echo $td_template_layout->close_all_tags();

Post count: 20685

Well the solution is somewhat old, the problem would be that the ad box shortcode has changed. Try it like this

[td_block_ad_box spot_id="custom_ad_2"]

Post count: 135

Seems to work fine. But doesn’t appear on mobile. Could you tell me which code should I add?

Post count: 20685
Post count: 205

The below Ad-code shows in Homepage and Page/2, 3, 4 too
So I just want to show in the Ad-code on Homepage only.

$adcounter++;
if (is_home()) {
if ($adcounter == 5) {
echo do_shortcode(‘[td_block_ad_box spot_id="custom_ad_1"]‘);
}
}

Post count: 20685

You could try it like this, instead of the is_home use this condition

if (is_front_page() and !is_paged())

Viewing 10 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic.