调用蛞蝓来显示猫
我有一个 div,其背景图像根据我的 WordPress 类别更改位置:
div.cat-links a.cat-log {
background-position: 20px 5px;
}
div.cat-links a.cat-a day in the life {
background-position: -163px 5px;
}
图像的代码正在此处复制:
<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>
在上面的示例中,它适用于第一个类别“log”,因为它是单个单词类别。然而,它对于我的“生活中的一天”类别不起作用。很公平,所以我需要做的是调用 slug 来调用图像。
我知道 WordPress 的示例中,slug 取代了类别,但我正在努力实现它,并且希望得到一些帮助。谢谢。
PS:这与 OMG Ubuntu 上的灰色类别选项卡效果完全相同。他们明智地使用了单字类别名称!
I have a div whose one background image changes position 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'. Fair enough, so what I need to do is call the slug to call the image instead.
I am aware of Wordpress examples where the slug replaces the category but I'm struggling to implement it and would appreciate some help with this. Thank you.
PS: This is exactly the same effect as the grey category tabs on OMG Ubuntu. They have sensibly used single-word category names!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经设法找到解决方案。
这是一种将 slug 称为类别的有用方法,可以解决 Wordpress 中多个单词的类别问题。关键是使 slug 和类别名称相同,并在 slug 中的每个单词之间添加“-”。这确实意味着我必须将类别“测试,测试...”更改为“测试测试”,并使用“测试-测试”,因为它无法处理缩写。
I've managed to find the solution.
This is a useful way of calling the slug as the category, getting round the problem of categories in Wordpress with more than one word. The key is to make the slug and the category name identical, with '-' in between each word in the slug. It does mean that I had to change my category 'Testing, testing...' to 'testing testing', with the slug 'testing-testing' because it can't cope with abbreviation.