• Resolved mikeyswede

    (@mikeyswede)


    Was asked to create a new topic
    Anyway

    Hi
    I’ve asked before (about a year ago) but not experienced enough to follow the directions
    I just don’t get it
    Anyway continued trying to figure this thing out
    I am using a child theme called MH NewsMagazine to the theme MH Magazine lite
    In the child theme I did put a copy of the content-single.php
    So far no problems but when I added the code to the line <?php mh_magazine_lite_featured_image(); ?> I got 2 images on the page
    One where the featured images is and below the full sized image – clickable but way to big
    I wanted the lightbox to work on the featured image
    This is how I wrote it
    

    <?php mh_magazine_lite_featured_image();

    // Link post thumbnail to full-size image.
    if ( has_post_thumbnail() ) {
    $thumbnail = [
    // URI of full-size post thumbnail image.
    ‘uri’ => get_the_post_thumbnail_url( null, ‘full’ ),
    // HTML to display post thumbnail.
    ‘img’ => get_the_post_thumbnail(),
    ];
    // Build thumbnail link.
    $thumbnail[‘link’] = sprintf( ‘%s‘, esc_attr( $thumbnail[‘uri’] ), $thumbnail[‘img’] );

    // Display full-size image in lightbox when clicked.
    if ( function_exists( ‘slb_activate’ ) ) {
    $thumbnail[‘link’] = slb_activate( $thumbnail[‘link’] );
    }

    // Display post thumbnail.
    echo $thumbnail[‘link’];
    }
    ?>`

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • I had the same problem, and with me what happened is that the theme was still displaying the featured image, then SLB would display a second time.
    You need to get rid of the first display, in your case I guess it’s somewhere before the code you copied.

    I couldn’t see the problem in the link you gave though, everything seemed normal to me.

    Thread Starter mikeyswede

    (@mikeyswede)

    Yeah I know it works that way but I would like to keep the featured image and be able to click on it to enlarge
    Or an alternativ solution is to alter the way the image is shown so it shows a 16×9 scale of the image and full image on click

    • This reply was modified 2 years, 11 months ago by mikeyswede.
    Thread Starter mikeyswede

    (@mikeyswede)

    Fixed the above by changing part of the code to this
    ‘img’ => get_the_post_thumbnail( $post_id, array(678, 381, true) ),

    Now my question is how the get the caption (if there is one) back underneath the image

    Plugin Author Archetyped

    (@archetyped)

    Yes, the reason there are two images from your intial code sample is that the theme’s mh_magazine_lite_featured_image() outputs the post thumbnail to the page, then the code you added to the template also outputs the post thumbnail.

    Removing mh_magazine_lite_featured_image() from the template is the first step. That will remove the non-linked thumbnail image from the page.

    If you want to match the thumbnail image originally displayed by the theme, you can use mh-magazine-lite-content as the thumbnail’s size in the custom code (rather than manually setting the thumbnail’s dimensions).

    Original:

    'img' => get_the_post_thumbnail(),
    

    Updated:

    'img' => get_the_post_thumbnail( null, 'mh-magazine-lite-content' ),
    

    The post thumbnail’s caption is retrieved using get_the_post_thumbnail_caption() (documentation). You can also look at the code for the theme’s mh_magazine_lite_featured_image() function to get the exact code used for the default thumbnail output and match it with your custom code as desired.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Featured Images to work with SLB’ is closed to new replies.