我正在尋找一種方法將css樣式賦予給wordpress循環中的元素。wordpress循環中的樣式僞元素
我特別嘗試將背景圖像添加到僞元素,其中背景圖像來自WordPress的帖子。最後,我希望在每一個環形的帖子上都有不同的背景圖片。
這裏的問題是,所有:: before元素獲取相同的背景圖像(從循環中的最後一篇文章)。
任何想法?
謝謝!
<?php $posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'post',
'order' => 'ASC',
));
if($posts): ?>
<?php foreach($posts as $post): setup_postdata($post); ?>
<div class="gradient" >
<?php the_title(); ?>
</div>
<style>
@supports (mix-blend-mode: lighten) {
.gradient {
display: inline-block;
position: relative;
color: #000;
background: #fff;
mix-blend-mode: multiply;
}
.gradient::before {
content: '';
display: block;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-image: url(<?php the_field('text-background'); ?>);
pointer-events: none;
}
.gradient::before {
mix-blend-mode: screen;
}
}
</style>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
我想你也可以做到這一點,但如果有一個頁面上有很多?需要創建一個循環。但是,這也是有效的。 – Adrianopolis
你必須創建一個循環來遍歷每個帖子自己的自定義背景圖像。更好的解決方案是有一個通用的漸變類,無論你需要自定義背景,你都可以通過style =「background-image:url(<?php the_field('text-background');?>)」來應用它相關元素 – fppz
這個工程!感謝你們!!! –