Fli
09-23-2013, 09:39 AM
If you want to let an html/php code / banner / text be visible only in certain Wordpress categories, you can setup this using PHP code below:
code:
<?php if ( is_category( 'category1') ): ?>
code/text for category1
<?php elseif ( is_category( 'category2') ): ?>
code/text for category2
<?php else: ?>
code/text visible for rest categories / pages
<?php endif; ?>
example:
<?php if ( is_category( 'hostgator-coupon') ): ?>
Another <a href="http://actnowdomains.com/hosting-packages.htm">reliable hosting provider</a> with affordable packages is Act Now Domains.
<?php elseif ( is_category( 'hostgator-control-panel') ): ?>
<!-- Insert code for cat ad here -->
Looking on how Hostgator control panel looks like or you wish to login this panel now? Its the best to use Google which can answer almost any question of ours.
<?php else: ?>
<!-- Insert code for generic ad here -->
Coupons for your hosting purchase can be found in the header of this website.
<?php endif; ?>
The proper category name you can see in Wordpress / Posts / categories (slug name)
Installing code
1)
If you want to add the above code into your blog sidebar, you can do it by installing Wordpress plugin named "Samsarin PHP widget" or any other which allows adding PHP code into sidebar widgets. After installing, go to: Wordpress / Appearance / Widgets and drag/drop this new Samsaring widget to your active widgets. Then paste your PHP code above + save.
2)
adding this code directly into template: Wordpress / Appearance / Editor / Sidebar (sidebar.php) ... or any other .php file. While editting original php files, you should first backup its text if you need to restore it in case something went wrong.
code:
<?php if ( is_category( 'category1') ): ?>
code/text for category1
<?php elseif ( is_category( 'category2') ): ?>
code/text for category2
<?php else: ?>
code/text visible for rest categories / pages
<?php endif; ?>
example:
<?php if ( is_category( 'hostgator-coupon') ): ?>
Another <a href="http://actnowdomains.com/hosting-packages.htm">reliable hosting provider</a> with affordable packages is Act Now Domains.
<?php elseif ( is_category( 'hostgator-control-panel') ): ?>
<!-- Insert code for cat ad here -->
Looking on how Hostgator control panel looks like or you wish to login this panel now? Its the best to use Google which can answer almost any question of ours.
<?php else: ?>
<!-- Insert code for generic ad here -->
Coupons for your hosting purchase can be found in the header of this website.
<?php endif; ?>
The proper category name you can see in Wordpress / Posts / categories (slug name)
Installing code
1)
If you want to add the above code into your blog sidebar, you can do it by installing Wordpress plugin named "Samsarin PHP widget" or any other which allows adding PHP code into sidebar widgets. After installing, go to: Wordpress / Appearance / Widgets and drag/drop this new Samsaring widget to your active widgets. Then paste your PHP code above + save.
2)
adding this code directly into template: Wordpress / Appearance / Editor / Sidebar (sidebar.php) ... or any other .php file. While editting original php files, you should first backup its text if you need to restore it in case something went wrong.