How to Display Category Specific Content in WordPress

Ads

One thing I love about WordPress is the great flexibility it offers in terms of designing custom themes and for this all the credit goes to WordPress Template Tags.

Recently I ran into a problem where I wanted to monetize the posts in my Gadgets category with TTZmedia ads while keeping the normal Google Adsense ads on all other posts. This is when I found the in_category template function which lets you display category specific content in WordPress.

The function is simple and very easy to use. Just use it in the Loop on any template file and it should work file.

<?php if ( in_category('category_id') ): ?>
// Some category specific PHP/HTML here
<?php endif; ?>

More detailed info and examples can be found on the link below:

http://codex.wordpress.org/Template_Tags/in_category

This can be helpful to monetize posts from certain categories with specific ads and can also be used to display information about a particular category.

A live implementation of this template function can be seen here on Sizlopedia. If you visit any post that belongs to the Gadgets category you will see targeted product ads while in other cases you will see the normal Google Adsense ads.

  • http://www.teknobites.com Ram

    Thats a good trick. You can also use templates for categories, then you can style or display information specific to that category

  • http://www.stumbledcore.uni.cc hassan

    Thanks a lot its really gonna help me in my search for latest stumbles for my site.

  • http://devilryu386.blogspot.com/ Rommel

    Interesting guide. Thanks for the detailed guide on how to embed Google Adsense Ads to categories. Is there other parts in WordPress where you can embed Ads?

  • http://www.sizlopedia.com Dj Flush

    @Rommel

    The best position to embed Google ads is above the content and below the title of article. There you get the highest click through rates.

  • http://camillesourgetrarebooks.com antiquarian books

    Thank you for this information. :)

  • http://euro-bijverdienen.be/ Kris

    Pfjieuw, i was almost giving up on this, but after reading your text i knew it was possible and where to look, so a big thanks for this post!

    It's hard being a novice in php :)

  • http://euro-bijverdienen.be/ Kris

    Pfjieuw, i was almost giving up on this, but after reading your text i knew it was possible and where to look, so a big thanks for this post!

    It's hard being a novice in php :)

  • http://www.newsbythepeople.com Taylor

    There's a huge problem with this a subcategories.

    For example: If I display something in Football News… It will also display in the subcategory Reggie Bush News, and all other sub categories, when Football News is the parent category.

    I'm not sure how to fix this problem, but any help would be totally sweet. :)

  • Shonari

    This does not work on homepage…only on single or archive page :(

  • http://xdwebsolutions.com/category/blog/ XD Web Solutions

    I was just getting ready to ask my twitter network how to do this but found your post first! Glad I did because it’s EXACTLY the information I needed about how to serve ads/content for different categories! Thanks!