Hi
To display a different header ad depending by category you need to edit the ads.php file and add a set of conditions like here: http://screencast.com/t/bFwpJ40a2D
if (is_category('New Look 2015')){
echo do_shortcode('[td_block_ad_box spot_id="custom_ad_1"]');
}elseif (is_category('Street Fashion')){
echo do_shortcode('[td_block_ad_box spot_id="custom_ad_2"]');
}elseif (is_category('Style Hunter')){
echo do_shortcode('[td_block_ad_box spot_id="custom_ad_3"]');
}
You need to replace the current categories names with your names. This code will display different header ad on the category page. If you want the same implementation for posts you need to use this function: in_category(): https://codex.wordpress.org/Function_Reference/in_category
Thanks!
-
This reply was modified 10 years by
Andrei L..
Hi
For pages you need to use is_page() function: https://codex.wordpress.org/Function_Reference/is_page Note that for the front page the function is: is_front_page() https://codex.wordpress.org/Function_Reference/is_front_page
Thanks!
Hi
Is it possible to do the same for the Newspaper theme? Basically I need different ads for each unit on each category.
Thanks
Hi Andrei
Thanks for the response but the reason I asked was because the ads.php file doesn’t seem to exist in the Newspaper theme so I wondered if it was possible and if so what file I need to edit.
Thanks
Neil
Hi
The file ads.php can be found here in Newspaper theme: http://screencast.com/t/Bz15Ilun65Z The code it’s a bit different then the one from Newsmag but the modifications can be done in the same way.
Thanks!
Hi
Found that now thanks. If I want to change the code for all ads in all spots where do I find that please. So I want to be able to change the sidebar ads and those that appear in the posts and all others based on categories. Where do I find that in the code please?
Hi
To display article ad depending by post’s category you need to edit td_module_single_base.php and modify the get_content() function: http://screencast.com/t/uspUfbvnJPD The sidebar ad and custom ads cant’t be displayed on posts depending by categories with the actual implementation of the theme. You will need to create a custom sidebar for each particular sidebar ad that you want to display, than assign the sidebar to posts from that category. For example if you want to display in sidebar ad X for posts from category Y, create a sidebar which contains the ad X and assign it to all posts from category Y.
Hope this help.
Thanks!
First Of all, thank you for your tips, they work like a charm!
The only problem I have encountered right now with this solution is that every time I enter a post on a specific category is still shows me the generic header banner, instead of the category banner, how can I make the posts of each category to include the desired banner?
Hi
Make sure you added the condition in the right file, corresponding with the header style used. Also check if the category added in condition is the same with the exact name of that category registered here: http://screencast.com/t/WNvWv7HSQ One last thing: if the post belong to several categories then you need to add all this categories in condition using an array like this:
if (is_category((array('cat 1', 'cat 2'))
Hope this help.
Thanks!
Hello Again Andrei
I checked the header style used and it’s correct (In my case I am using Header Style 7) So I am asuming this style won’t suddenly change between posts so there is no need to modify any other header style, is that correct?
I tried what you told me, but it’s not working either, (actually If I use the category names instead of the category slug, the script doesnt work in any case) I tried using the category names, the category slugs, changed the order and still it shows the default header banner but in the category pages I modified before the script works…
The Files I have modified are “ads.php”, “header-style-7.php”, “td-config” & “td-panel-ads” (the last ones to add more custom ad spaces) is there any other file (or files) that I need to modify in this case?
By the way, I am modifying the Newspaper Theme not the Newsmag.
Thanks.
Hi
Sorry for misunderstanding.
The above solutions works only when a category page it’s displayed. If you want to change the header ad for o post from a specific category then you need to use the in_category() function. Here is a basic example for caribbean and destinations categories on my side: http://screencast.com/t/NDVOIEvs1bg
<?php
if (in_category(array('caribbean','destinations'))){
echo do_shortcode('[td_block_ad_box spot_id="custom_ad_1"]');
}
else{
locate_template('parts/header/ads.php', true);
}
?>
This code will load a different header ad for all posts which belong to caribbean and destinations categories.
Note: if you want to change the ad for a post from a specific category the required function is in_category() but if you want to change it for a category page then you have to use is_category().
Hope this help.
Thanks!
-
This reply was modified 10 years by
Andrei L..
Hi again, no problem.
Yes, that last change did it, no problems any more, thank you very much for your help!
Hi
At the moment this is the best way to load a different ad as the theme does not have an option built in. We consider extending theme’s flexibility in the future and it’s possible to add such a feature bu I can’t promise anything yet as we have a long implementation list and we have to take them one by one.
Thanks for your message!
I am trying this for newspaper theme and getting this error:
Parse error: syntax error, unexpected ‘else’ (T_ELSE) in /home/content/n3pnexwpnas02_data02/30/3153330/html/wp-content/themes/Newspaper/parts/header/ads.php on line 7
This is how my final ads.php looks like..
<div class=”td-header-rec-wrap”>
<?php// show the header ad spot
if (in_category(‘Automotive’)){
echo do_shortcode(‘[td_block_ad_box spot_id="custom_ad_4"]‘);
else {
locate_template(‘parts/header/ads.php’, true);
}
?>
</div>
What am i doing wrong.?
Hi
That happens because in your code is missing a bracket. Replace that code with this one, it should work fine:
<div class="td-header-rec-wrap">
<?php
// show the header ad spot
if (in_category('Automotive')) {
echo do_shortcode('[td_block_ad_box spot_id="custom_ad_4"]');
}
else {
locate_template('parts/header/ads.php', true);
}
?>
</div>
Thanks!
-
This reply was modified 10 years by
Andrei L..
Hi,
I followed all these instructions and got everything working. Except my ad does not show on Desktop, only on mobile.
http://oscarmariobeteta.com/category/noticias/ This is where the custom leaderboard ad should go. It only shows in mobile.
HI
I’ve checked the indicated page and the header ad is displayed fine on desktop: http://screencast.com/t/8XqkVu1coM6 If you still have this issue try to clear all caches including browser’s cache then test the site again.
Thanks!
Is there an easy way to display ads on all category pages in the description? Desktop, mobile, tablet.
-
This reply was modified 9 years by
searchspot.
Hello searchspot,
If you want to insert an ad into a category description, you should use the do_shortcode method to do that. First of all, you should install the Seo Yoast plugin because this plugin allows you to use the TinyMCE editor and there you should add your ad, like this -> http://screencast.com/t/xyu0tmV2tX and the result is here -> http://screencast.com/t/tiVrrPjaoNAM Ensure that you have added your Ad code in the Custom Ad 1 from theme panel if you want to bring some results, like this -> http://screencast.com/t/Aw1yAN9Fk
Thanks for your understanding!
Hello,
I´ve attempted to add the customer ad 1 to this page by category, but the banner isn´t visible. I’ve used if (is_category Any advice?
http://giblad.com/category/food/
Thank you
