Featured image in a category
Support › MB Term Meta › Featured image in a category
- This topic has 6 replies, 2 voices, and was last updated 3 years, 1 month ago by
Long Nguyen.
-
AuthorPosts
-
February 23, 2022 at 11:04 PM #34080
victoria de clasca
ParticipantHello
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
February 24, 2022 at 6:31 AM #34088victoria de clasca
ParticipantI'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%;
}February 24, 2022 at 6:32 AM #34089victoria de clasca
ParticipantI am working on the archive Category template,
sorry I didint say that
February 24, 2022 at 6:33 AM #34090victoria de clasca
Participantin oxygen
February 24, 2022 at 12:31 PM #34095Long Nguyen
ModeratorHi,
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-valueIn 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/February 24, 2022 at 5:10 PM #34100victoria de clasca
ParticipantThank 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%;
}February 24, 2022 at 9:36 PM #34110Long Nguyen
ModeratorHi,
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.
-
AuthorPosts
- You must be logged in to reply to this topic.