How to insert ads between posts on the main categories and in the archives?

Posted in: Newspaper
Post count: 7

How to insert ads between posts on the main categories and in the archives?

Post count: 14

I would also be interested in learning the answer to this.

Post count: 6600

Hi,

Add this code:

$adcounter = 0;

and

$adcounter++;
    if (is_category() or is_archive()) {
        if ($adcounter == 2 or $adcounter == 4 or $adcounter == 6) {
        echo do_shortcode('[td_ad_box spot_id="custom_ad_1"]');
        }
    }

in the loop.php file, like this: http://screencast.com/t/DsXKbb9C

This will add an ad after 2 post, 4 post and 6 posts on the category page and archive page also if you want you can change this simply by removing or by adding $adcounter == variable or changing it’s value as you want. Also notice that the code for these ad goes in the Ads > Custom Ad 1 > Your Custom Ad 1 in Theme Panel.

You will also need to add this custom CSS in Theme Panel > Custom CSS:

.category .td-a-rec-id-custom_ad_1{
margin-bottom: 30px !important;
}

.archive .td-a-rec-id-custom_ad_1{
margin-bottom: 30px !important;
}

You will get this result: http://screencast.com/t/nuHrZ7zhGY

Thanks

  • This reply was modified 12 years by Lucian.
Post count: 7

Thank you

Post count: 10

Is it possible to do this using a module? My homepage is using block 21 with a load more button, and I’d like to display ads between posts. Is this possible with your theme?

Thanks in advance!

Post count: 22421

Hello,
you can use ads the same way with a do_shortcode function. For a block 21 you need to edit module 16 and add this code to it:
<?php echo do_shortcode('[td_block_ad_box spot_id="custom_ad_1"]')?> like so: http://screencast.com/t/bmQjF5k6
This will insert an ad after every post in the module: http://screencast.com/t/xkKmZTqi9
It will need a bit of css to position it though if this is what you want.
Thank you!

Post count: 10

Awesome thank you.
I’d like to change it up a little and only show an ad every 6 posts. Where can I set the adcounter to zero to have it loop properly for module 16?

Post count: 22421

Hello,
In order to do that, you will have to use the ad counter above and adapt it to a block 21 by altering this function: http://screencast.com/t/zsobDTbfbD
Unfortunately you will need to get some help if you cannot manage it as time does not allow us to offer any custom work.
Thank you!

Post count: 10

Okay, I customized so the loop is working but the shortcode is not being executed?
See screenshot
https://gyazo.com/ffd7add35c45e07dd10ef26b95904e1b

Thanks in advance

Post count: 22421

Hello,

Unfortunately as i replied above, you will need some extra help as this task falls beyond what support can offer you. If you cannot manage to alter the function by yourself, you can hire a freelancer from sites like studio.envato.com as we cannot offer any custom work at the moment.

Thank you.

Post count: 2

Hi Lucian,

I have been able to add this code but the screencast is no longer showing. Would it be possible to recapture the image so I can add the above code to the loop.php in the right location?

Many thanks,
Kevin

Post count: 22421

Hello,
As this topic is 1 yer old, the code will not work anymore as the shortcodes were changed. The method still applies though. You can use it like so: http://screencast.com/t/FoVvUOVY
I hope this helps.
Thank you!

Post count: 2

Works perfectly, thank you!

Post count: 99

If I need to add the adcounter in the block22, which module do I go edit?

Thank you

Post count: 99

Found it, module 17

Post count: 99

Hi I was able to add the shortcode to the module 17 and the ad show up, unfortunately it show right after every post. see screeshot http://prntscr.com/bkpwpi

This is how my code look in module17

function render() {
ob_start();
?>

<div class="<?php echo $this->get_module_classes();?>">
<div class="meta-info-container">
<?php echo $this->get_title();?>

<div class="td-module-image">
<?php echo $this->get_image('td_696x385');?>
<div class="td-module-meta-holder">
<div class="td-left-meta">
<?php echo $this->get_author();?>
<?php echo $this->get_date();?>
</div>
<?php echo $this->get_comments();?>
</div>
<div class="td-category-corner">
<?php if (td_util::get_option('tds_category_module_17') == 'yes') { echo $this->get_category(); }?>
</div>
</div>

<div class="td-excerpt">
<?php echo $this->get_excerpt();?>
</div>

<div style="padding-top:30px; margin-bottom: -30px; ">
<?php echo do_shortcode('[td_block_ad_box spot_id="custom_ad_1"]')?>
</div>

<div class="td-read-more">
href;?>"><?php echo __td('Read more', TD_THEME_NAME);?><i class="td-icon-menu-right"></i>
</div>
</div>

</div>

<?php return ob_get_clean();
}
}
, is there anything else I need to add so the ad can be display on every 5 posts?

This is the last step before I can launch the site.

Please guide me to the right direction?

Thank you for your support.

Post count: 22421

Hi,

Unfortunately we have not tested this with blocks so I cannot say for sure if it will work. You will have to get some help on this task fro a developer. You can hire one from sites like studio.envato.com.

Thank you!

Post count: 108

Hello

Thanks, I success to have custom ads on default loop, archive, tag and category after 3 posts. this will be great if we can place custom ads on block for various customization in tagdiv composer.

I do some experiment to place custom ads on block 18. I put this code:


//insert adsense
$adcounter++;
if ($adcounter == 2 or $adcounter == 4 or $adcounter == 6){
$buffy .= do_shortcode('[td_block_ad_box spot_id="custom_ad_2"]');
}

On this file http://www.screencast.com/t/pmWcAIXu the custom ads show up on the block 18 after 2, 4 and 6 from posts lists http://www.screencast.com/t/wsT6hLeT. Also see live result is perfect http://www.screencast.com/t/5Ta26Pjoy. But the code is still not perfect, it’s because I can’t access tagdiv composer anymore hahaha http://www.screencast.com/t/sNKNE1u1o

It would be better if someone volunteered to help me to make this code works on the block 18 file. If this code is working, we can put custom ads in another block file. 🙂

Post count: 35449

Hi,

Please increase the wp_memory_limit and the tagDiv Composer will work just fine.
https://www.screencast.com/t/HwsGvfpzK
https://forum.tagdiv.com/requirements-for-newspaper/

Thank you.

Post count: 108

Hello calin

Before I add that code for block 18, the tagdiv composer is work just fine, when I add it, I can’t access tagdiv composer anymore http://www.screencast.com/t/sNKNE1u1o

When I remove that code from block 18 file, the tagdiv composer back to normal again.

I want to add this code http://www.screencast.com/t/pmWcAIXu without getting any error on tagdiv composer, I don’t know what’s wrong with that code, the result is perfect on block 18 http://www.screencast.com/t/5Ta26Pjoy, but tagdiv composer is cannot be using again.

I am using localhost before I made any change on my website to avoid any error.

Thank you for your response. 🙂

Post count: 55

Hello. Please tell me how and where to place the Adsens advertising code, so that the ad unit is displayed in the category-headings on the site as here – https://null-24.com/category/wordpress-plugin? To advertising blocks were repeated through one. Please tell me how do I do the same? Screenshot – https://yadi.sk/i/4TNiX6oPoF_UWw

Post count: 35449

Hi,

On that website is use tagDiv Cloud Library, get from there a template for Categories, edit it and set categories blocks after that set ad box and so on.

Thank you for your understanding.

Post count: 55

Thanks, but I don’t understand.))))

Post count: 35449

Hi @WebMasterhi,

What I mean is that on your example that page of category in order to have a line of category posts, one of ads, you can get a category Template from tagDiv Cloud Library
https://forum.tagdiv.com/tagdiv-cloud-library-plugin/
You can edit the category template with TD Composer
https://www.screencast.com/t/dGXQN21Ww4Qx
https://www.screencast.com/t/QebUiMHvKdb
Hope this will help you better.

Thanks.

Post count: 10

Hi,
I attempted to add the a ads between posts using the tagdiv composer by adding a block and then ads and then another block however since both blocks are from same category, the posts are getting doubled over. How can I add the ads between posts on category page without having posts duplicated?
Thanks

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