I'm looking for a way to give css-style to an element within a wordpress loop.
I specifically try to add a background image to a pseudo element, where the background image comes from the wordpress post. In the end I want to have different background images on every looped post.
The problem here is that all ::before elements gets the same background image (from the last post in the loop).
Any ideas?
Thank you!
<?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; ?>
