Custom Fields
Re-Envisioned
Support MB Views How to show a featured image on in an archive view?

  • Creator
    Topic
  • #20507
    Resolved EddyPiV
    Participant

    Hi,

    With MT Term Meta I have added featured images to my categories and custom taxonomies.

    I would like to see these replacing the header images from my theme when showing the archive pages for the categories / taxonomies.
    My theme doesn’t recognize this term meta added field (obviously), and the closest I got with MB Views was to render The whole page layout, including header and footer. But then I am losing also the main menu and my widget area’s. Even my website name and flavicon disappear.
    How to replace the theme’s header image with the featured image of the term?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Author
    Replies
  • #20509
    Long Nguyen
    Moderator

    Hi Eddy,

    What is the theme that you are using? If it is premium theme, please send a copy of this theme to this support form https://metabox.io/contact/. I can help you to replace the header image with the image of the custom field after looking into the code of the theme.

    #20513
    EddyPiV
    Participant

    Hi,

    Yes I am using a Pro theme. Trying to send it to you, but the recaptcha on the contact page is hard to pass, as the header with the instruction whhat to do is not shown properly. see attached. https://share.getcloudapp.com/2Nu5Ppv2

    So if you can help me there first…

    #20514
    EddyPiV
    Participant

    Just managed to send it to you through another browser.

    #20524
    Long Nguyen
    Moderator

    Hi Eddy,

    I’ve checked the code of the theme Materialis Pro and find a way to change the default background image of the archive page with the image of a custom field.

    • Create a simple image field such as single_image and assign it to a taxonomy.
    • Add this code to the file functions.php in the child theme folder.
    add_action( 'materialis_before_header_background', function() {
        $term_id = get_queried_object_id();
        $feature_image = rwmb_meta( 'single_image', array( 'object_type' => 'term' ), $term_id );
        if( !empty( $feature_image ) ) {
            ?>
            <style type="text/css">
                .header-wrapper .header {
                    background-image: url(<?php echo $feature_image['full_url']?>) !important;
                }
            </style>
            <?php
        }
    } );

    For more information, please follow the documentation below.
    https://docs.metabox.io/extensions/mb-term-meta/#getting-field-value
    https://docs.metabox.io/fields/single-image/

    #20546
    EddyPiV
    Participant

    Hi Long, thanks so much for your help. Much appreciated.

    I noticed that within the archive view, for render “Only the post content area” it does not show the featured image. Actually, none of my settings are applied. It seems completely ignored.

    For render “The layout between header and footer” the featured image is shown, but after the theme’s header image, not replacing it.

    I am not a real developer, so I prefer to stick as close as possible the the theme, hence using render “Only the post content area”. But how to have my view settings applied, as well as the featured image replacing the theme’s header image?

    I hope you can help me further.

    #20547
    Long Nguyen
    Moderator

    Hi,

    The theme uses the CSS code to display the image as a background cover image that’s why I need to check the code and the code in my previous reply uses the CSS code to override the theme’s style. See my screenshots for more information.
    https://share.getcloudapp.com/yAuYkK7x
    https://share.getcloudapp.com/NQugxNkZ

    #20595
    EddyPiV
    Participant

    Hi Long, the developer of the theme has provided me with a solution.
    Thanks for your help.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.