Support Forum
Support › MB Term Meta › Featured image in a category
Hello
I am adding a Cusom field in the category taxonomy.
I am not coding,
I am working on the panel of metabox all time.
I've used, image select, background and url. None of them are working.
The case is that is not calling the image-
I am using oxygen, I select the metabox field name in the dynamic data field (url).
Tahnks
I've looked at the documentation, and I found this code
It only works in some categories, is there something wrong?
I'm not sure if the code of categories is 'categories', how do I know?
<?php
$terms= get_the_terms( $post->ID, 'category');
$background_image = get_term_meta( $terms[0]->term_id, 'single_image_taxonomy', true );
if ($background_image) {
$link_image = wp_get_attachment_image_src( $background_image, 'full' );
$link_image_source = $link_image[0];
}
else {
$link_image_source = get_term_meta( $terms[0]->term_id, 'single_image_taxonomy', true );
}
if ( !empty( $terms ) ){
$term = array_shift( $terms );
}
?>
<div class="card-slider">
">
</div>
CSS
.card-slider {
position: relative;
overflow: hidden;
height: 300px;
width: 100%;
vertical-align: middle;
}
.thumbnail-cat {
object-fit: cover;
position: absolute;
top: 0;
height: 100%;
width: 100%;
}
I am working on the archive Category template,
sorry I didint say that
in oxygen
Hi,
If you want to display the field image
of the taxonomy category, please follow this documentation https://docs.metabox.io/extensions/mb-term-meta/#getting-field-value
In case of using Oxygen Builder, please reach out to them if you have any issues with installation, configuration, compatibility, or usage.
Refer to our support policy https://support.metabox.io/topic/support-policy/
Thank you,
I now using the code of your documentation for featured image,
and something is not working,
can you check the code if theres somethimg missing? the name categories is correct? should I refer to other word?
http://sergig5.sg-host.com/guias-monta%C3%B1a/escalada/
<?php
$terms= get_the_terms( $post->ID, 'category');
$background_image = get_term_meta( $terms[0]->term_id, 'single_image_taxonomy', true );
if ($background_image) {
$link_image = wp_get_attachment_image_src( $background_image, 'full' );
$link_image_source = $link_image[0];
}
else {
$link_image_source = get_term_meta( $terms[0]->term_id, 'single_image_taxonomy', true );
}
if ( !empty( $terms ) ){
$term = array_shift( $terms );
}
?>
<div class="card-slider">
">
</div>
CSS
.card-slider {
position: relative;
overflow: hidden;
height: 300px;
width: 100%;
vertical-align: middle;
}
.thumbnail-cat {
object-fit: cover;
position: absolute;
top: 0;
height: 100%;
width: 100%;
}
Hi,
Firstly, please share the code that creates the custom fields on your site. If you are using the builder, please read more here https://docs.metabox.io/extensions/meta-box-builder/#getting-php-code
Then I will help you to add the code to the template of the theme to show the image on the archive page.
The code on your post is to show the image of the category on the single post page, not on the archive page.
Please notice that, if you use the Oxygen Builder, it will ignore loading theme files.