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.
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
Thanks Lucian !! I copied the loop.php to child theme folder, added the code as advised, setup Custom ad 1 & it works just fine !! 🙂
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?
-
This reply was modified 11 years by
paulberrow.
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!
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!
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!
-
This reply was modified 11 years by
Alin [tagDiv].
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.
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!
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!
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.
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.
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.
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!
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.