Wordpress Gurus, I need Your Ass........... istance.

efeezy

New member
Oct 5, 2007
5,250
136
0
50
Here's what I'm trying to do, and I'm sure there's a simple solution, but I just can't get it working.

On my archive/cat pages, I have an ad section at the top of the page which is directly above the archive/category results.

What I would like to do is have a specific ad block shown depending on the archive category.

So lets say I have a Golf category. I've made a php file with my golf specific ads and I want to use something like <?php include("golfads.php"); ?> to show those ads. But I'll need to have it determine if the page is the Golf category by using <?php if (is_category('golf')) : ?>.

How do I merge these two pieces into one piece of code that will pull the golfads.php page when the cat is golf. I have 30 categories that I would need to set up just like this. If someone could throw me a bone here (not literally), I'd be eternally grateful.
 


Code:
<?php
$cat_name = get_query_var('cat');
if ($cat_name == '') { $cat_name = 'default'; }

include($cat_name . '_ads.php');
?>
 
Code:
<?php
$cat_name = get_query_var('cat');
if ($cat_name == '') { $cat_name = 'default'; }

include($cat_name . '_ads.php');
?>

Looks good. Forgive the stupid question, but say the category was golf. Which one's would I need to replace with golf.

I tried

Code:
<?php
$cat_name = get_query_var('golf');
if ($cat_name = 'golf') { $cat_name = 'default'; }

include($cat_name . '_ads.php');
?>

with the ad page being names golfads.php, but it's not showing anything on the golf page.
 
Not sure about that code bu Categories have numbers.. so you may have to use the number.. You get the number at the edit category I guess. I did something similar while I was editing the revolution theme long time back
 
Still trying to get this working if anyone has any other suggestions. Matt & I thought we had something figured out, but I just couldn't get it working.
 
You can make a unique template for each category, but since you have 30 categories it wouldn't be ideal for future updates.

category-slug.php
category-id.php

Works for tags too:

tag-slug.php
tag-id.php

I would probably write a long if else statement personally, but I'm not a coder. And I would hire a coder if this solution loaded really slowly.

<?php

if(is_category( 'Golf' )){
include("golfads.php");
}elseif(is_category( 'Football' )){
include("footballads.php");
}else{
include("default.php");
}

?>

If you have some other way that should work, but does not, are you using any custom queries instead of the normal loop? Those can cause trouble by feeding the wrong $post-ID.