I think you have to use elseif and else in there rather than all those “ifs”… without going into what it is you are trying to do, did you try:
<?php
if (in_category(‘education’)) {
{echo ‘class=”educationcontent”‘;}
elseif (in_category(‘healthcare’)) {
{echo ‘class=”healthcarecontent”‘;}
elseif (in_category(‘business & industry’)) {
{echo ‘class=”businesscontent”‘;}
elseif (in_category(‘public sector’)) {
{echo ‘class=”publiccontent”‘;}
else {//the default action if not any of the above }
?>
I’m no php programmer, but…
and I’d move the php inward, since you KNOW you want a class written, there’s no need to put that part into the code (saving bytes) because you could write
<div class=”<?php /*all the logic above*/ ?>”>
just my two. hth, and good luck with it!
I might suggest something along these lines …
First, make use of category templates (if you are not), here is some information on them: http://codex.wordpress.org/Category_Templates
Also, be sure to use the body_class() function, here is some reading on it: http://www.nathanrice.net/blog/wordpress-2-8-and-the-body_class-function/
Combined you will have a specific template being called for each category, and the body_class() function will provide a specific class you will be able to style.
Without a link to your blog it appears from your sample code above you are adding your “category class” to the post, not the page itself, whereas the body_class() function provides classes that encompass the entire page … especially useful for “page” specific backgrounds.
I do not believe you will even need to worry about using the if statements you are trying to implement (above).
Hope this helps some.
Thanks for replying after all that my initial code worked I just needed to alter a part in the wordpress dashboard. Thanks Cais now I know about the body_class_function it will make future projects easier.
Except now it has brought me to another problem – when I click on the link on the sidebar it directs me to the page and posts that I want except the sidebar is now empty. Here is the code which I have used in the sidebar.php
<ul><?php
if (get_post_meta($post->ID,'categorynumber', true)) {
$catid = get_post_meta($post->ID,'categorynumber', true);
wp_list_categories("child_of=" .$catid . "&title_li=");
}
?>
</ul>
but now I want to tell it that if it is on a page which is a child category still display the categories of the parent.
I tried using at the end of the above code
else {
if (in_category ('16,10,5,18'))
wp_list_categories ('parent_of=' .$catid . "&title_li=" );
but does not work,
I hope what I am trying to do makes sense
if not let me know I will explain in more detail
}
Here is the codex page for wp_list_categories: http://codex.wordpress.org/Template_Tags/wp_list_categories … there is no ‘parent_of’ parameter.
You might also consider custom sidebar templates in your category template files. Here is another link into the codex: http://codex.wordpress.org/Function_Reference/get_sidebar
Hope that helps to sort things out.