Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Nelio Software

    (@nelio)

    Hi! You simply need to redefine a function called leaf_get_post_image. Here you have the new definition:

    function leaf_get_post_image($image_id = null, $post_id = null, $use_attachments = false, $url = null, $size = 'large') {
      global $id,$blog_id;
      $thumbnail_id = get_post_thumbnail_id();
      $post_id = ( $post_id == null ) ? $id : $post_id;
      $attachment = array();
    
      // If a URL is specified, use that.
      if ($url)
        return $url;
    
      // If image_id is specified, use that.
      elseif ($image_id)
        $attachment = wp_get_attachment_image_src( $image_id, $size );
    
      // Check to see if NextGen Gallery is present.
      elseif(stripos($thumbnail_id,'ngg-') !== false && class_exists('nggdb')){
        $nggImage = nggdb::find_image(str_replace('ngg-','',$thumbnail_id));
        $attachment = array(
          $nggImage->imageURL,
          $nggImage->width,
          $nggImage->height
        );
      }
    
      // If not, let's use the post's featured image.
      elseif ( has_post_thumbnail( $post_id) ) {
        if ( function_exists( 'uses_nelioefi' ) && uses_nelioefi( $post_id ) )
          return nelioefi_get_thumbnail_src( $post_id );
        else
          $attachment = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), $size );
      }
    
      // Otherwise, and only if we want to, just use the last image attached to the post.
      elseif ( $use_attachments == true ) {
        $images = get_children(array(
          'post_parent' => $post_id,
          'post_type' => 'attachment',
          'numberposts' => 1,
          'post_mime_type' => 'image'));
        foreach($images as $image) { $attachment = wp_get_attachment_image_src( $image->ID, $size ); }
      }
    
      // If there is no image, use the default image (available filter: leaf_post_image_none).
    
      if (isset($attachment[0])) {
        $post_image_uri = $attachment[0];
      } elseif ( 'slider' == $size ) {
        $post_image_uri = apply_filters( 'leaf_slider_image_none', get_template_directory_uri() . '/images/no-image.jpg' );
      } else {
        $post_image_uri = apply_filters( 'leaf_post_image_none', get_template_directory_uri() . '/images/no-image-small.jpg' );
      }
    
      // If no image, return now
      if ( $post_image_uri == apply_filters( 'leaf_slider_image_none', get_template_directory_uri() . '/images/no-image.jpg' ) || apply_filters( 'leaf_post_image_none', get_template_directory_uri() . '/images/no-image-small.jpg' ) )
        return $post_image_uri;
    
      // If MU/MS install, we need to dig a little deeper and link through the blogs.dir.
      if ('IS_MU') {
        $imageParts = explode('/files/', $post_image_uri);
        if (isset($imageParts[1])) {
          $post_image_uri = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1];
        }
      }
    
      return $post_image_uri;
    }

    The previous function is almost an exact copy of the original version, except for how we manage the elseif ( has_post_thumbnail( $post_id) ) block. In that elif block, we’ve added a small check: if ( uses_nelioefi( $post_id ) ) return nelioefi_get_thumbnail_src( $post_id );.

    You can edit this function directly in the theme (file includes/theme-plugins.php, line 153+), or you can create your a child theme and write the previous function in functions.php. I recommend you use the second option; otherwise, your changes will be lost when the theme is updated.

    Finally, I’d like you to note that the carousel might not work that well with external featured images… I suppose the carousel expects the featured images to have certain dimensions (which WordPress can guarantee, but external featured images don’t).

    Please, let us know if this worked!

    Plugin Author Nelio Software

    (@nelio)

    Hi! Did our solution work?

    Plugin Author Nelio Software

    (@nelio)

    Since we got no answer from OP, but the solution worked in our environment, we’ll close the thread.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Not Working With Leaf Theme’ is closed to new replies.