开发者

CSS class assigned to a taxonomy term

开发者 https://www.devze.com 2023-02-25 19:12 出处:网络
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

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 rig开发者_运维问答ht?

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消