• Resolved vatsalthegreat

    (@vatsalthegreat)


    The MultiNews theme show only local featured image and not external featured image made by your plugin.

    The images which are uploaded locally are visible, others are not visible.

    There’s a file in framework folder named “function.php” there’s a code which I think needs to be edited. I have tried everything, but couldn’t make it work.

    function mom_post_image($size = 'thumbnail', $id='', $pid = '', $di = false){
    		global $post;
    		$image = '';
    
    		//get the post thumbnail
    		if ($pid == '') {
    			$pid = $post->ID;
    		}
    
    		if ($id != '') {
    			$image_id = $id;
    		} else {
    			$image_id = get_post_thumbnail_id($pid);
    		}
    		$image = wp_get_attachment_image_src($image_id,
    		$size);
    
    		$image = $image[0];
    
    		if ($image) return $image;
    
    		//if the post is video post and haven't a feutre image
    		global $posts_st;
    		$extra = get_post_meta($pid, $posts_st->get_the_id(), TRUE);
    
    		  $format = get_post_format($pid);
    		  if (isset($extra['video_type'])) { $vtype = $extra['video_type']; }
    		  if (isset($extra['video_id'])) { $vId = $extra['video_id']; }
    		  if (isset($extra['html5_poster_img'])) { $html5_poster = $extra['html5_poster_img']; } else { $html5_poster = ''; }
    
    		if($format == 'video') {
    			if($vtype == 'youtube') {
    			  $image = 'http://img.youtube.com/vi/'.$vId.'/0.jpg';
    			} elseif ($vtype == 'vimeo') {
    			$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$vId.php"));
    			  $image = $hash[0]['thumbnail_large'];
    			} elseif ($vtype == 'html5') {
    			  $image = $html5_poster;
    			} elseif ($vtype == 'daily') {
    					$image = 'http://www.dailymotion.com/thumbnail/video/'.$vId;
    			} elseif ($vtype == 'facebook') {
    					$image = 'https://graph.facebook.com/'.$vId.'/picture';
    
    			}
    
    		}
    
    		if($format == 'gallery') {
    		global $posts_st;
    		$extra = get_post_meta($id , $posts_st->get_the_id(), TRUE);
    		$slides = isset($extra['slides']) ? $extra['slides'] : '';
    		$image_id = isset($slides[0]['imgid']) ? $slides[0]['imgid'] : '';
    		$image = wp_get_attachment_image_src($image_id, $size);
    		$image = $image[0];
    		}
    
    		if ($image) return $image;
    
    		//If there is still no image, get the first image from the post
    		if (mom_option('post_first_image') == 1) {
    			if (mom_get_first_image($pid) !== '') {
    			return mom_get_first_image($pid,$size);
    			}
    		}
    
    		$default_image = get_template_directory_uri().'/images/no-image.jpg';
    			if (mom_option('post_default_img') == 1) {
    				if (mom_option('custom_default_img', 'url') != '') {
    					return mom_option('custom_default_img', 'url');
    				} else {
    						return $default_image;
    				}
    
    			} else {
    				if ($di == true) {
    					return $default_image;
    				} else {
    					return ;
    				}
    			}
    		}
    
    		function mom_get_first_image($id, $size = 'thumbnail') {
    	        $post_id = $id;
    	        $queried_post = get_post($post_id);
    			$first_img = '';
    			ob_start();
    			ob_end_clean();
    			$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $queried_post->post_content, $matches);
    			$first_img = '';
    			if (isset($matches[1][0])) {$first_img = $matches[1][0];}
    
    		  	global $mom_thumbs_sizes;
    			$w = isset($mom_thumbs_sizes[$size][0]) ? $mom_thumbs_sizes[$size][0] : '';
    			$h = isset($mom_thumbs_sizes[$size][1]) ? $mom_thumbs_sizes[$size][1] : '';
    		  	$first_img = vt_resize( '', $first_img, $w, $h, true );
    		  	if (isset($first_img['url'])) {
    				return $first_img['url'];
    			} else {
    				return '';
    			}
    
    		} 
    
    		function mom_post_image_full($size = 'thumbnail', $hd = '', $alt = '', $id = ''){
    			if (mom_post_image($size, $id) != '') {
    				if ($hd == '') {
    				$hd = $size;
    				}
    				if ($alt == '') {
    				$alt = esc_attr(get_the_title());
    				}
    				global $mom_thumbs_sizes;
    				$w = isset($mom_thumbs_sizes[$size][0]) ? $mom_thumbs_sizes[$size][0] : '';
    				$h = isset($mom_thumbs_sizes[$size][1]) ? $mom_thumbs_sizes[$size][1] : '';
    
    				//$w = ''; $h = '';
    
    				if( has_post_thumbnail() || mom_option('theme_thumb') != 1) {
    					$thumb = get_post_thumbnail_id();
    					$image = vt_resize( $thumb, mom_post_image($size, $id), $w, $h, true );
    					if($image['url'] != ''){
    						$output = '<img src="'.$image['url'].'" data-hidpi="'.mom_post_image($hd, $id).'" alt="'.$alt.'" width="'.$image['width'].'" height="'.$image['height'].'">';
    					} else {
    						$output = '<img src="'.mom_post_image($size, $id).'" data-hidpi="'.mom_post_image($hd, $id).'" alt="'.$alt.'" width="'.$image['width'].'" height="'.$image['height'].'" style="max-height:'.$h.'px;">';
    					}
    				} else {
    					$output = '<img src="'.mom_post_image($size, $id).'" data-hidpi="'.mom_post_image($hd, $id).'" alt="'.$alt.'" width="'.$w.'" height="'.$h.'">';
    				}
    					//$output .= 'SHARE_FROM_IMAGES';
    				echo $output;
    
    			} else {
    			return false;
    			}
    		}
    /*  ---------------------------------------------------------------------------- */

    Any help would be highly appreciated.

    Thanks in advance.

    https://ww.wp.xz.cn/plugins/external-featured-image/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter vatsalthegreat

    (@vatsalthegreat)

    It partially worked when I turned the option “Use first image as featured image” in the Theme settings page, and modified the code above like this:-

    //$w = ''; $h = '';
    
    				if ( function_exists( 'uses_nelioefi' ) && uses_nelioefi( $pid ) ) {
      $image = the_post_thumbnail( $pid );
    } else if( has_post_thumbnail() || mom_option('theme_thumb') != 1) {
    					$thumb = get_post_thumbnail_id();
    					$image = vt_resize( $thumb, mom_post_image($size, $id), $w, $h, true );

    But I am not fully satisfied with this tweak. If I turn off that option,”Use first image as featured image” in the Theme settings page”, the images disappear. Is there any other workaround/modification to the above code so that I can use any other external featured image other than the first one.

    Plugin Author David Aguilera

    (@davilera)

    Hi!

    I think you almost got it right. Instead of adding the new if block as you did:

    //$w = ''; $h = '';
    if ( function_exists( 'uses_nelioefi' ) ... {
    } else
    if ...

    Add it at the very beginning of your function:

    function mom_post_image_full($size = 'thumbnail', $hd = '', $alt = '', $id = '') {
      if ( function_exists( 'uses_nelioefi' ) && uses_nelioefi( $pid ) ) {
        $image = get_the_post_thumbnail( $pid, $size );
      } else if (mom_post_image($size, $id) != '') {
        ...

    This will probably fix your issue, because the first thing we’ll be checking is if the current post has an external featured image.

    On the other hand, please note I modified a couple of things:

    • Instead of using the function the_post_thumbnail, I’m using get_the_post_thumbnail. The former function prints an img tag directly, whereas the latter returns a string (which is what you need).
    • I added $size as the second parameter of get_the_post_thumbnail. I think it’s better to use it… but if you don’t like the final result, get rid of it and see if things look better.

    Please, let us know if this worked!

    Thread Starter vatsalthegreat

    (@vatsalthegreat)

    Hi David,

    Thanks for your reply. The parameter “get_the_post_thumbnail” you mentioned is not showing up the images at all, it removed the local images also.

    See
    https://postimg.org/image/ikrr7wien

    When I used, the_post_thumbnail, It gave me the images as earlier.

    See
    https://postimg.org/image/v0oh1nbqn

    It is the similar solution which I mentioned. It doesnt show up images when I turn off that option,”Use first image as featured image” in the Theme settings page.

    Kindly give me a code to get the external image without turning the first image theme option to on.

    Regards
    Vatsal

    Plugin Author David Aguilera

    (@davilera)

    Hey, you’re right. The original function mom_post_image_full ends like this:

    ...
      echo $output;
    } else {
      return false;
    }

    So, yes, it looks like the image is actually supposed to be “printed”. Then, use the_post_thumbnail directly, but do not assign to a variable (there’s no need to).

    Regarding the setting, I’m afraid you’ll have to figure out why the function is not called when the setting is disabled. There’s little I can do here; this deeply depends on your theme.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Plugin Not Working On MultiNews Theme’ is closed to new replies.