How to add ads in category pages

Posted in: Newspaper
Post count: 2

Hi,

I have setup ads in sidebar and have setup Ad inline code in Ads section which displays ad within content & on homepage, I have created an ad element though unable to do the same in Category pages. How can I setup inline ads in category pages i.e. after 4-6 articles, there is an ad & then rest of the articles follow.

Post count: 6600

Hi,

You can make this change in loop.php file and add this code: http://screencast.com/t/3e4ogIsjrP

$adcounter = 0; add this at the top of the loop like in the screenshot.

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

.. and this at the bottom like shown in the screenshot.

Should work like this: http://screencast.com/t/RerPylFiEqI
Make sure you set the ad to show up on category pages after and exact number of posts if you are using an layout which is displaying two posts or 3 posts depending of page layout.

Thanks

Post count: 2

Thanks Lucian !! I copied the loop.php to child theme folder, added the code as advised, setup Custom ad 1 & it works just fine !! 🙂

Post count: 224

Lucian, did i get you right that if i need to show the ad after each post i have to duplicate part of the code and change adcounter? Like this

if (is_category() && ($adcounter == 1)) {
echo do_shortcode(‘[td_ad_box spot_id=”custom_ad_1″]’);
}
if (is_category() && ($adcounter == 2)) {
echo do_shortcode(‘[td_ad_box spot_id=”custom_ad_1″]’);
}
if (is_category() && ($adcounter == 3)) {
echo do_shortcode(‘[td_ad_box spot_id=”custom_ad_1″]’);
}

UPD. It doesn’t work like this so how can i show it after each post?

Post count: 7909

Hi,

If you want to display the ad after each article you have to add the code like this: http://screencast.com/t/IrpjYTN0Jbr

Thanks!

Post count: 224

Thank you!
It works, but partly. As i found out the thing is i use ads which have to have kind of unic id so one ad can’t be shown on the same page more then 1 time. So i had to add 3 scripts in the custom ad fields in theme panel and i’m run out of free fields now:)

Is there any way i can add more than 3 custom ads?

About ads in category between description and posts i still can’t figure out how to do it with do_shortcode() function… Could you please provide a bit more information?

For now i just added my ad script in file category.php after this
default:
echo td_page_generator::wrap_start();
?>
<div class=”span8 column_container”>
<?php
//load the author box located in – parts/page-category-slider.php – can be overwritten by the child theme
locate_template(‘parts/page-category-slider.php’, true);
?>
It shows up in the place i need, but i’m not sure if it’s right to do it this way..

Thank you in advance!

Post count: 7909

Hi,

Please follow this topic to add more custom ads – https://forum.tagdiv.com/topic/sidebar-ads/#post-21850
If you want to use do_shortcode() function just paste this instead using ad script there:

<?php echo do_shortcode('[td_ad_box spot_id="custom_ad_1"]'); ?>

Just the number of custom ad that you want to display.

Thanks!

Post count: 62

Trying to add Custom Ad 1 to the top of category pages and Custom Ad 2 to bottom of pages. Code for loop.php is helpful but links to screen shots referenced in Lucian’s first post above are not working. Is there another place to find them? Was able to use the “$adcounter = 0;” or “$adcounter == 2)” terms to add an ad after 10 articles. Wondering how to make an ad appear at the very top of the page (below nav bar and above breadcrumbs) as this is typically where we insert Super Leaderboard ads.

Thanks!

  • This reply was modified 10 years by ninjaray.
Post count: 22421

Hi,

If you only need to insert one ad, not repeated after a number of posts, then you do not need to use the adcounter. You can simply use a do_shortcode function in the category template like so:
http://screencast.com/t/3AhOEXNl9lPl

<div class="mycustomclass">
    <?php echo do_shortcode('[td_block_ad_box spot_id="custom_ad_1"]');?>
</div>

It will need a few css adjustments to remove the bottom margin and add a top margin for it to position properly so you can use the custom class assigned to the div element.

As for the bottom ad you need to use the same procedure but this time place the code at the bottom of loop.php from the root directory.

I hope this helps.
Thank you!

Post count: 11

Hi there,

i tried to put ads in the loop of only tag pages as described above with the ad counter. I need to show an ad after post 2 and 4. It only returns this on the tag page after the 2nd post exerpt: [td_block_ad_box spot_id="custom_ad_5"].

Could you please advice how i can achieve that? Or where exactly i have to put the shortcode or a php function to get it working?

Thanks in advance!

Post count: 22421

Hello,

If you want to use the above solution for tag pages only, you can simply change the condition fgrom is_category to is_tag like so:

if (is_tag() && ($adcounter == 2)) {
echo do_shortcode('[td_ad_box spot_id="custom_ad_5"]');
}

It worked on my end like this: http://screencast.com/t/TGaJmPwLkxXy

I hope this helps.

Thanks.

Post count: 11

Hi Bogdan,

thanks for your help. I figured that changing the condition should do it. Unfortunately it didn’t work on my end.

On the tag page it returns [td_ad_box spot_id=”custom_ad_6″] after the specified post exerpt.

Here is the code in the loop.php:

if (have_posts()) {
while ( have_posts() ) : the_post();
$adcounter++;
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();

if (is_tag() && ($adcounter == 2)) {
echo do_shortcode(‘[td_ad_box spot_id=”custom_ad_6″]’);
}

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

I just added custom ad 6 & 7 but tried it with custom ad 5 too. Also tried it with the Ad inserter plugin which didn’t work either. Their support told me to try it with a php function.

Can you find what’s wrong? Why doesn’t it work? Is there another way?

Really appreciate your help on this.

Post count: 22421

Hi,
Sorry, i have not checked the shortcode itself. It’s the wrong shortcode (old) as this topic is kind of old and the solutions above are provided with the old custom ad shortcodes. Here is how the current shortcodes look like:
[td_block_ad_box spot_id="custom_ad_1"]
Sorry for the dumb mistake.

Post count: 11

Thanks Bogdan! It seems to work altough i don’t see an ad yet…probably takes a bit.

What’s the code like if i need to display 2 ads? Lets say after the 2nd and 4th exerpt?

Do i need to repeat the if part?

if (is_tag() && ($adcounter == 2)) {
echo do_shortcode(‘[td_block_ad_box spot_id="custom_ad_1"]‘);
}

if (is_tag() && ($adcounter == 4)) {
echo do_shortcode(‘[td_block_ad_box spot_id="custom_ad_2"]‘);
}

Appreciate one last tip here.

Thank you!

Post count: 22421

Here is an example of how it looks like on my end:
http://screencast.com/t/tAciKT0w and the code: http://screencast.com/t/zUiK17pvrP
Thanks.

Post count: 11

Great Bogdan! Thanks a lot! Awesome support!

Post count: 60

Thanks Luclan. The two screenshots expired. Can you send links to active screenshots?

Post count: 22421

Hi


@maxlaxoc

The screens are almost right above your reply…just take a look at my previous reply 2 posts up and you will see exactly how to implement the code.

Thank you!

Viewing 18 posts - 1 through 18 (of 18 total)
The forum ‘Newspaper’ is closed to new topics and replies.