Featured images not appearing in portfolio galleries

Hi Team,

I have a bunch of portfolio items that all have multiple images assigned/attached to them that appear as a slideshow at the top of each post. These work really well except for the fact that the image that is assigned as the FEATURED IMAGE for the post doesn’t appear in the gallery.

I’ve tested with disabling plugins etc and the issue is still occuring - is there a simple code change I can make to queue the featured image into the portfolio gallery?

Example portfolio piece: http://mbs.com.au/projects/st-lukes-catholic-college/

Thanks!
Michael

Hi There,

Can you please upload the same image with a different name that you have upload for feature post.
The gallery excludes the feature image. Please let us know if that works or you can provide us your login details
so that we can check the issue for you.

Thanks

Hi Basanta,

That works but there are over 30 portfolio items and we are going to be adding significantly more - having to upload the featured image twice for every portfolio item is not a great solution.

Is there a code solution/setting to update to make that featured image appear in the slider by default?

Cheers,
Michael

Hi there,

Please try adding this code to your child theme’s functions.php and test it again, but make sure to clear your caches before testing.

  function x_featured_gallery() {

    $stack     = x_get_stack();
    $fullwidth = ( in_array( 'x-full-width-active', get_body_class() ) ) ? true : false;

    $args = array(
      'order'          => 'ASC',
      'orderby'        => 'menu_order',
      'post_parent'    => get_the_ID(),
      'post_type'      => 'attachment',
      'post_mime_type' => 'image',
      'post_status'    => null,
      'numberposts'    => -1
    );

    $attachments = get_posts( $args );

    if ( $attachments ) {
      echo '<div class="x-flexslider x-flexslider-featured-gallery man"><ul class="x-slides">';
        foreach ( $attachments as $attachment ) {
          echo '<li class="x-slide">';
            if ( $fullwidth ) {
              echo wp_get_attachment_image( $attachment->ID, 'entry-fullwidth', false, false );
            } else {
              echo wp_get_attachment_image( $attachment->ID, 'entry', false, false );
            }
          echo '</li>';
        }
      echo '</ul></div>';
    }

  }

Thanks!

1 Like

Thanks Rad, that change worked perfectly.

On behalf of my colleague, you’re welcome. Cheers! :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.