分配给分类术语的 CSS 类
想象一个具有 4 个不同分类术语的博客。
我想显示“所有博客项目”,但每个带有“设计”一词的博客项目都会有不同的外观。所以我想要的是为节点内的行提供一个 CSS 类。我说得对吗?
我可能以一种粗俗、非常黑客的方式做到了这一点,但事实是:
if (isset($fields["tid"]->content)) {
unset($classes);
unset($class);
unset($classarray);
$classarray = explode(",", $fields["tid"]->content);
echo '<div class="';
foreach ($classarray as $class) {
$class = str_replace('<span class="field-content">', "", $class);
$class = str_replace("</span>", "", $class);
$class = str_replace(" ", "", $class);
echo strtolower($class) . " ";
unset($class);
}
echo '">';
}
else {
echo "<div>";
}
然后我在文件末尾有一个 标记。
这确实需要您在定义内容类型时将分类详细信息添加为内容,并使用一些 CSS 隐藏它。
好吧,我希望这可以帮助某人,尽管它的形式很糟糕。
Imagine a blog with 4 different taxonomy terms.
I want to display "all blog items," but every blog item with the term "design" will have a different look. So what I'd want is to have a CSS class for rows within a node. Am I saying that right?
I probably did this in a gross, really hacky way, but here it is:
if (isset($fields["tid"]->content)) {
unset($classes);
unset($class);
unset($classarray);
$classarray = explode(",", $fields["tid"]->content);
echo '<div class="';
foreach ($classarray as $class) {
$class = str_replace('<span class="field-content">', "", $class);
$class = str_replace("</span>", "", $class);
$class = str_replace(" ", "", $class);
echo strtolower($class) . " ";
unset($class);
}
echo '">';
}
else {
echo "<div>";
}
Then I had a </div>
tag at the end of the file.
This does require you to add the taxonomy details as content when you define your content type, and hide it with some CSS.
Well, I hope this might help someone, even though it's bad form.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要显示“所有博客项目”,您需要创建一个视图。
然后,您可以为该视图创建自定义模板,对其进行更改以将分类术语作为类名称插入到 HTML 中。
To display "all blog items," you'll need to create a view.
You can then create a custom template for that view, altering it to insert the taxonomy term as a class name into the HTML.