Anyway to do this in Wordpress?

smartalex4

Junior Member
Joined
Jun 5, 2009
Messages
163
Reaction score
57
I would like to know if there is a way to add Ads based on categories?

For example, is there a way I could add Chicago specific ads to all my post that to pertain to Chicago, and New York specific ads to the New York post...etc....without having to go into each post one by one?

Thanks in advance
 
There probably are some plugins which can do this. i suggest searching for such plugin :)
 
I've been searchin' but so far...no dice.
 
if your ads are in widgets the you can install the widget-logic plugin and then you can control
were to display witch ad and you can do that like that:

for example say your Chicago category id is 25 the just add
PHP:
is_category(25)
to the Chicago ads widget
and it will only show on that category
the same goes for any other category you want.

if your add are not widgets the you can use this conditional function in your theme files
like this
PHP:
if(is_category(25)){
//display Chicago adds here
}
else{
//other ads
}
 
CLIENT SIDE

Add the js as described here to your WP: http://www.maxmind.com/app/javascript_city

Make a simple check in javascript on the city and write your ad accordingly.

SERVER SIDE

If you feel like using php you can use this simple snippet AFTER downloading the proper huge library from: http://www.maxmind.com/app/geolitecity (the php version, of course...). Edit the code below and put it in the WP template wherever it needs to show up. This just prints the name of the city.. Add your own checks to it and "echo" what needs to be displayed accordingly

The folloiwing SUUUUPER-simple code assumes you uploaded geoipcity.inc, geoipregionvars.php and the dat file in the home dir of your webserver. Enjoy!

Code:
<?php
///////////////////////////////////////////////////////////////////////////////
// This code demonstrates how to lookup the country, region, city, postal code, 
// latitude, and longitude by IP. Designed to work with GeoIP/GeoLite City
// Note that you must download the New Format of GeoIP City (GEO-133). 
// The old format (GEO-132) will not work.
// 
// Based on sample_city.php enriched by a genius
///////////////////////////////////////////////////////////////////////////////
include("geoipcity.inc");
include("geoipregionvars.php");

$gi = geoip_open($_SERVER['DOCUMENT_ROOT'] . "/GeoLiteCity.dat",GEOIP_STANDARD);
$record = geoip_record_by_addr($gi,$_SERVER['REMOTE_ADDR']);

echo $record->city; // Your Checks Abt The City Here...
?>
 
Back
Top