Wordpress Category Specific Ads

tetley07

New member
Oct 10, 2007
43
1
0
Hey,

I'm looking for a way to do something with wordpress but since I know shit about code I don't really know where to start. Hopefully there's a plugin or easy solution already out there.

What I want to do is display different ads for different categories within a wordpress autoblog. For example, if I have a blog about golf and I have 3 categories:
golf clubs
golf balls
golf tips

For every post pulled into golf clubs category, I want ad 1 to be displayed on all those posts - obviously being an ad/banner/text ad/whatever specifically for golf clubs

For every post pulled into golf tips, an ad for a book to be displayed on those pages and so on for all other categories.

At the moment, either the sidebar or within the post itself, it doesn't really matter which one, I'll be happy for now just to find an easy way to have targetted ads placed automatically.

I can't place the ads manually for each post because it's an autoblog and I can't put a sitewide sidebar ad because it will not be targeted for each post (in some cases, the categories will be very different from one another).

So anyone know how to do this? I know shit about code so the solution is probably real simple and I just can't see it, lol.

Cheers
 


If anyone has something for this, let me know.

I do it real ghetto right now .... put this code in your sidebar.php

Code:
        <?php if (in_category('golf-clubs') && !is_home()) { ?>

                <div align="center">
                <a href="#" target="_blank">
                <img src="#.gif" border="0" />
                </a>
                </div>
                
        <?php } ?>

        <?php if (in_category('golf-clubs') && !is_home()) { ?>
                  <div align="center">
                <a href="#" target="_blank">
                <img src="#.gif" border="0" />
                </a>
                </div>


        <?php } ?>
 
^^ That works pretty well actually. What I found was that if I use that code and go to a post in the first category it pulls the image/ad I select, but if I go to then go directly to a post in the second category, it wants to show ads from both categories for some reason. Any idea why?
 
^^ That works pretty well actually. What I found was that if I use that code and go to a post in the first category it pulls the image/ad I select, but if I go to then go directly to a post in the second category, it wants to show ads from both categories for some reason. Any idea why?

Are your posts in both categories? That could be why. I only use one category per post on the blog from that example so i haven't run into that problem.
 
Try the code below:

Code:
<?php if (is_category('golf-clubs')) { ?>

<<insert html code for golf club ads>>

<?php } elseif (is_category('golf-balls')) { ?>

<<insert html code for golf balls ads>>

<?php } elseif (is_category('golf-tips')) { ?>

<<insert html code for golf tips ads>>

<?php } else { ?>

<<any other html code to show for undefined categories>>

<?php } ?>

Works awesome for me and you can add more categories by adding
<?php } elseif (is_category('xxxxxxxx')) { ?> :D
 
I use oiopublisher for that (they added a small function); its not free but its worth the purchase, hit me up with a PM and i'll try and get you a discount code for a few $ off.

Though saying that you have a working code sample above so your call.
 
Do this the non-ghetto way. Invest an hour in setting it up right, then it's much easier to manage:

1) Install OpenX (10 mins if you know what you're doing, ~60 if you don't)
2) Make a zone in OpenX for each category
3) Put your campaigns and ads in OpenX, and link them to the zones you want them to show in
4) Write a little piece of PHP that pulls the right zone from OpenX for the category you're on.

Done.

The code for item 4 should *not* be a bit of code that looks like:
Code:
if (in_category('some_category_name')) {
   do something for some_category_name; 
}
if (in_category('some_other_category')) {
   do something for some_other_category; 
}
This is lame. Better (pseudo) code would be:
Code:
$zoneId = findZoneIdForThisCategory(); 
showOpenxZone($zoneId)
If anyone actually wants to do this, I'll help you write the code to pull in the OpenX zones as these are only examples.

m
 
^^ Is this really the best way to do it? Sounds like I should have listened when I saw this the first time....

I've spent an hour already dicking around with my previous php and the above, and it's not consistent when you have posts two sub categories deep.
 
I'd be trying to find the id for the category if I were you. Unfortunately I'm short on time at the moment, otherwise I'd find out how to do this in WP for you.
 
Do this the non-ghetto way. Invest an hour in setting it up right, then it's much easier to manage:

1) Install OpenX (10 mins if you know what you're doing, ~60 if you don't)

....

That's really handy, nice one.

If ya don't want the hassle of installing & upgrading OpenX (or the footprint) they do a hosted version now btw.
 
Thanks for the suggestions... installing openx now, man that's a large script.

Hosted version takes a day or two for an invite, but I like the idea of that.

Tried to pull based on category id, but it still doesn't work in the format listed above when you have Main cat>subcat1>subcat2>post, especially if the post is in more than one category.
 
Thanks a ton for the suggestions everyone, I'll probably just use the ghetto set up for the moment as this is only for 1 project but definitely good to know there's a few options to do this. Cheers.