admin管理员组文章数量:1431406
I have below piece of code in style.css file (website : ) I am looking for option to have different background-image for different post/question category.
.question-content-text {background-image:(../logo);}
We cannot write php inside css style so could you please help/guide how can this be achieved?
I have below piece of code in style.css file (website : https://askpuzzle) I am looking for option to have different background-image for different post/question category.
.question-content-text {background-image:(../logo);}
We cannot write php inside css style so could you please help/guide how can this be achieved?
Share Improve this question asked Apr 19, 2019 at 11:44 Avinash PatelAvinash Patel 398 bronze badges1 Answer
Reset to default 0You have to have something to target, so that means adding a class with the necessary information for your styles.
I recommend adding categories (or terms from your custom taxonomy) to the body classes. You can do this with a simple filter. This targets single templates and pulls terms from the category taxonomy. You can easily change either of these to suit your needs.
add_filter( 'body_class', 'my_body_class' );
function my_body_class( $classes ) {
if ( is_single() ) {
$categories = get_the_terms( get_the_ID(), 'category' );
if ( $categories ) {
$category_slugs = array();
foreach ( $categories as $category ) {
$category_slugs[] = 'cat-' . $category->slug;
}
$classes = array_merge( $classes, $category_slugs );
}
}
return $classes;
}
This will add new classes to your body tag like cat-uncategorized
.
本文标签: customizationHow to have different background image based on post category
版权声明:本文标题:customization - How to have different background image based on post category 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745572968a2664159.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论