Tagged: acf, advanced custom fields, category, category image, taxonomy
Hi,
I use AdvancedCustomFields for several things with ENFOLD.
In this case I would like to show a category image in the archive.php of ENFOLD.
So far, so good – it works in that way fine, that I can upload a category image in the backend.
But something with my PHP output in the archive.php seems to be not right: it does not show the image.
What I have done:
1. adding a field group in ACF for category images as described in the documentation.
2. The settings are (pay attention to the “Return Value”!):
3. Then I added in archive.php directly after get_header();
this:
// get the current taxonomy term
$term = get_queried_object();
// vars - ACF for showing Images and Color in Category Backend
$image = get_field('image', $term);
$color = get_field('color', $term);
4. also in archive.php I added as described in the documentation this snippet wit ENFOLD’s CSS:
<style type="text/css">
.entry-content-wrapper .post-title {
color: <?php echo $color; ?>;
}
<?php if( $image ): ?>
.categoryheaderimage {
background-image: url(<?php echo $image['url']; ?>);
}
<?php endif; ?>
</style>
<div class="categoryheaderimage"> </div>
Since my PHP is not so good, there seems to be a mistake in the output of the image, if you could please take a look.
Maybe my trial to output the image via
<div class=”categoryheaderimage”> </div>
is not so ideal for ENFOLD?
My site is not yet online, so please login, see data below.
Thank you.
Update:
I figured it out, it was just a mistake in the CSS for the category image – it needed a height value.
— SOLVED —