demonboy
05-03-2011, 08:51 AM
Hi all, my first post here.
I have a div whose background image changes according to my Wordpress categories:
div.cat-links a.cat-log {
background-position: 20px 5px;
}
div.cat-links a.cat-a day in the life {
background-position: -163px 5px;
}
The code for the image is being reproduced here:
<div class="cat-links">
<?php foreach((get_the_category()) as $category) {
echo '<a rel="category-tag" href="'.get_category_link($category->cat_ID).'" class="cat-'.$category->cat_name.'">'.$category->cat_name.'</a>';
} ?>
</div>
In my example above it works for the first category, 'log', because it is a single word category. It doesn't work, however, for my category 'a day in the life'. For some reason this code is drawing the category name from the Wordpress name, not the slug. The slug, in this case, is 'adayinthelife'. I have tried:
a.cat-a day in the life
a.cat-'a day in the life'
a.cat-adayinthelife
a.cat-a_day_in_the_life
...none of which work. I am trying to emulate the code from OMGUbuntu (http://www.omgubuntu.co.uk) where little grey category icons appear by the excerpt on the home page.
I have a div whose background image changes according to my Wordpress categories:
div.cat-links a.cat-log {
background-position: 20px 5px;
}
div.cat-links a.cat-a day in the life {
background-position: -163px 5px;
}
The code for the image is being reproduced here:
<div class="cat-links">
<?php foreach((get_the_category()) as $category) {
echo '<a rel="category-tag" href="'.get_category_link($category->cat_ID).'" class="cat-'.$category->cat_name.'">'.$category->cat_name.'</a>';
} ?>
</div>
In my example above it works for the first category, 'log', because it is a single word category. It doesn't work, however, for my category 'a day in the life'. For some reason this code is drawing the category name from the Wordpress name, not the slug. The slug, in this case, is 'adayinthelife'. I have tried:
a.cat-a day in the life
a.cat-'a day in the life'
a.cat-adayinthelife
a.cat-a_day_in_the_life
...none of which work. I am trying to emulate the code from OMGUbuntu (http://www.omgubuntu.co.uk) where little grey category icons appear by the excerpt on the home page.