Answer the question
In order to leave comments, you need to log in
How to write if the category is x, then the picture is x?
There is a page where different products from different categories are collected
. I have the following code to display posts (product cards):
<?php
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('category_name=for_heating&showposts=-1' . '&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="col-lg-4 <?php $posttags = get_the_tags();
if( $posttags ){
foreach( $posttags as $tag ){
echo $tag->slug. ' ';
}
} ?>">
<div class="card_item" id="spoiler1">
<div class="content-item">
<div class="title_svg">
<h4 class="h4_cards">
<?php the_title() ?>
</h4>
<div class="svg_card">
<?php the_post_thumbnail( 'full', $svg_attr ); ?>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
Answer the question
In order to leave comments, you need to log in
If on the knee, then like this:
function wpp_change_svg_img_color( $url, $color ) {
$content = file_get_contents( $url );
$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
$doc->loadXML( $content ) or die( 'Failed to load SVG ' . $url );
$paths = $doc->getElementsByTagName( "path" );
foreach ( $paths as $path ) {
$path->setAttribute( 'fill', $color );
$path->setAttribute( 'style', 'fill:' . $color );
$content = $doc->saveXML( $doc );
}
return $content;
}
$url = the_post_thumbnail_url( 'full' ); // url миниатюры
$color = '#000000'; #нужный вам цвет
printf( '<img src="%s" alt="">', wpp_change_svg_img_color( $url, $color) );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question