Help with Wordpress Coding please

SFD

Free Member
Nov 2, 2008
1,275
436
I have a line of code which displays which categories a post belongs to

PHP:
<h3 class=cat_title><?php the_category(', '); ?> &raquo</h3>
this brings up a line at the top of each post, example:

headline, featured, mens, £100+


I am trying to alter the code so it does not display 'headline' and 'featured'

I know in wordpress there is exclude=3 + include=3 etc but they don't seem to apply to this function.

I have done lots of searching and the best I have come up with is

PHP:
<?php foreach((get_the_category()) as $cat) { if (!($cat->cat_ID=='52')) echo '<a href="' . get_bloginfo('url') . '/category/' . $cat->category_nicename . '/">'. $cat->cat_name . '</a>' . ', '; } ?>
Where I replace 52 with the category number. The problem with this code though is I can only exclude 1 category.

Does anyone know what code I am after, I have searched and searched but can't find a simple solution to exclude more than 1 category.

Thanks
 
Hi there

you need to create a new method/function in your page which takes a parameter of your $cat variable. This method will then return a boolean true or false value.

The method will then check the passed in cat and if it matches headline or featured then it will return false, other wise return true.

Here is a starter for you off the top of my head, though i haven't done php for years!

function Show($i)
{

switch ($i) {
case "headline":
return false;
break;
case "featured":
return false;
break;
default:
return true;
}
}

cheers

Jamie
 
  • Like
Reactions: SFD
Upvote 0
try using single_cat_title( '', false );
also replace &raquo; with & #187; (removespace)
 
Last edited by a moderator:
  • Like
Reactions: SFD
Upvote 0
Hi there

you need to create a new method/function in your page which takes a parameter of your $cat variable. This method will then return a boolean true or false value.

The method will then check the passed in cat and if it matches headline or featured then it will return false, other wise return true.

Here is a starter for you off the top of my head, though i haven't done php for years!

function Show($i)
{

switch ($i) {
case "headline":
return false;
break;
case "featured":
return false;
break;
default:
return true;
}
}

cheers

Jamie

That is slightly too technical for me, thanks for the help though.

try using single_cat_title( '', false );
also replace &raquo; with & #187; (removespace)

Cheers Kev, I replaced the &raquo but the rest didn't work, well , it did work but not the way I wanted it to.

I've managed to work around it now in my naviagtion so it's no longer a problem.:)
 
Upvote 0

Latest Articles