• Resolved bellaelysium

    (@bellaelysium)


    Hi,

    I am a fan of your plugin and did a little tweaking on the function.php have been using it with my Soledad theme with no problem. But after I update the theme, the feature images thumbnails are grey out.

    Somehow, it seems that it is not able to show thumbnails with external featured images urls taken from my last image of my post (it works only when I add the pictures to the WP media gallery. I have forgot how I tweak back then (playing around) and hence, decided to seek help here.

    From theme function.php:

    /**
     * Get the featured image size url from post
     *
     * @since 3.1
     * @developed PenciDesign
     */
    if ( ! function_exists( 'penci_get_featured_image_size' ) ) {
    	function penci_get_featured_image_size( $id, $size = 'full' ) {
    		if ( ! has_post_thumbnail( $id ) ) {
    			return '';
    		} else {
    			$image_html = get_the_post_thumbnail( $id, $size );
    			preg_match( '@src="([^"]+)"@', $image_html, $match );
    			$src = array_pop( $match );
    
    			return $src;
    		}
    	}
    }
    
    /**
     * Get the featured image size url based on featured image full url
     *
     * @since 3.1
     * @developed PenciDesign
     */
    if ( ! function_exists( 'penci_get_image_size_url' ) ) {
    	function penci_get_image_size_url( $image_url, $size = 'full' ) {
    		global $wpdb;
    		$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
    		$image_id = $attachment[0];
    		$image_thumb = wp_get_attachment_image_src($image_id, $size);
    		$image_thumb_html = $image_thumb[0];
    
    		return $image_thumb_html;
    	}
    }

    Where do I insert the _nelio_url function and change the way it get the image from your nelio metabox instead of wp metabox so that it will just grab the image from the last image of the post?

    It works perfectly before so I am sure it will work here too. Hope you can help!

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author David Aguilera

    (@davilera)

    Hi!

    The first function should work out of the box. But if it doesn’t, you can check if _nelioefi_url is set and, if it is, return that instead:

    
    function penci_get_featured_image_size( $id, $size = 'full' ) {
      $efi_url = get_post_meta( $post_id, '_nelioefi_url', true );
      if ( is_string( $efi_url ) && strlen( $efi_url ) ) {
        return $efi_url;
      }
      // followed by the original code
    }
    

    The other function is slightly more complicated, but I don’t think you’ve ever tweaked that. Try with the first one and let us know!

    BTW, you can add that tweak in a custom plugin of yours (instead of adding it in your theme’s functions.php file). If you create this custom plugin, you won’t lose your customizations when the theme is updated.

    Thread Starter bellaelysium

    (@bellaelysium)

    Hi,

    Thanks for the reply!

    DO I use that code you gave and replace with the first function of the theme code?
    I am noob in this but what you mean by custom plugin of mine?

    Thanks!

    Plugin Author David Aguilera

    (@davilera)

    I see. Then create a new file named nelio-penci-support.php with the following content:

    
    <?php
    /**
     * Plugin Name: Nelio Tweaks to Support Penci Theme
     * Version:     1.0.0
     *
     * Author:      Nelio Software
     * Author URI:  https://neliosoftware.com
     * License:     GPL-2.0+
     * License URI: https://www.gnu.org/licenses/gpl-2.0.txt
     *
     * @author     David Aguilera <[email protected]>
     * @since      1.0.0
     */
    
    // If this file is called directly, abort.
    if ( ! defined( 'WPINC' ) ) {
    	die;
    }
    
    function penci_get_featured_image_size( $id, $size = 'full' ) {
      // Nelio Tweak.
      $efi_url = get_post_meta( $id, '_nelioefi_url', true );
      if ( is_string( $efi_url ) && strlen( $efi_url ) ) {
        return $efi_url;
      }
    
      // Original function code.
      if ( ! has_post_thumbnail( $id ) ) {
        return '';
      } else {
        $image_html = get_the_post_thumbnail( $id, $size );
        preg_match( '@src="([^"]+)"@', $image_html, $match );
        $src = array_pop( $match );
        return $src;
      }
    }
    

    and save it in wp-content/plugins/. This will create a plugin you can enable in your site. Once it’s enabled, this function will “overwrite” the one in your theme.

    Thread Starter bellaelysium

    (@bellaelysium)

    Hello,

    I have tried that but it doesn’t work.

    Thread Starter bellaelysium

    (@bellaelysium)

    Okay, I add in one more line and it works great.
    if ( ! function_exists( 'penci_get_featured_image_size' ) ) {
    However, it only works if I set the feature image in my post. However, it doesn’t automatically set feature image by taking the last image of my post. I have like many older entries which I can’t do it one by one.

    Is there any solution? It works last time.

    Plugin Author David Aguilera

    (@davilera)

    Is your theme free? Where can I download it? I need the theme to (try to) find a solution.

    Thread Starter bellaelysium

    (@bellaelysium)

    Hi,

    My theme is not free. It’s Soledad theme (in case you have it). DOes it works with other free themes by mass auto set featured images using the last image of post?

    If yes, let me know how I can send it to you.

    Plugin Author David Aguilera

    (@davilera)

    I was just asking to download a copy.

    Okay, I add in one more line and it works great: if ( ! function_exists( 'penci_get_featured_image_size' ) ).

    Are you sure about this? I mean, does it only work with the if clause? I’d say it’s unnecessary in the plugin you’ve just created, because of the second part of your message:

    However, it only works if I set the feature image in my post. However, it doesn’t automatically set feature image by taking the last image of my post. I have like many older entries which I can’t do it one by one.

    That’s entirely possible. I applied a solution that only retrieves manually-set featured images. If you want the plugin to retrieve them automatically, we need to change the first portion of the function:

    
    function penci_get_featured_image_size( $id, $size = 'full' ) {
      // Nelio Tweak.
      if ( class_exists( 'Nelio_Content_External_Featured_Image_Helper' ) ) {
        $aux = Nelio_Content_External_Featured_Image_Helper::instance();
        $efi_url = $aux->get_nelio_featured_image( $id );
        if ( is_string( $efi_url ) && strlen( $efi_url ) ) {
          return $efi_url;
        }
      }
    
      // Original function code.
      if ( ! has_post_thumbnail( $id ) ) {
        return '';
      } else {
        $image_html = get_the_post_thumbnail( $id, $size );
        preg_match( '@src="([^"]+)"@', $image_html, $match );
        $src = array_pop( $match );
        return $src;
      }
    }
    
    Thread Starter bellaelysium

    (@bellaelysium)

    Are you sure about this? I mean, does it only work with the if clause?

    Somehow, it just deactivate and said its fatal error. I have no idea why when I add this line it works. Okay here’s the code I put in so far, but it gave me fatal error.
    Parse error: syntax error, unexpected end of file in …

    <?php
    /**
     * Plugin Name: Nelio Tweaks to Support Penci Theme
     * Version:     1.0.0
     *
     * Author:      Nelio Software
     * Author URI:  https://neliosoftware.com
     * License:     GPL-2.0+
     * License URI: https://www.gnu.org/licenses/gpl-2.0.txt
     *
     * @author     David Aguilera <[email protected]>
     * @since      1.0.0
     */
    
    // If this file is called directly, abort.
    if ( ! defined( 'WPINC' ) ) {
    	die;
    }
    
    function penci_get_featured_image_size( $id, $size = 'full' ) {
      // Nelio Tweak.
      if ( class_exists( 'Nelio_Content_External_Featured_Image_Helper' ) ) {
        $aux = Nelio_Content_External_Featured_Image_Helper::instance();
        $efi_url = $aux->get_nelio_featured_image( $id );
        if ( is_string( $efi_url ) && strlen( $efi_url ) ) {
          return $efi_url;
      }
    
      // Original function code.
      if ( ! has_post_thumbnail( $id ) ) {
        return '';
      } else {
        $image_html = get_the_post_thumbnail( $id, $size );
        preg_match( '@src="([^"]+)"@', $image_html, $match );
        $src = array_pop( $match );
        return $src;
      }
    }
    

    Is there anything wrong with it?

    Thread Starter bellaelysium

    (@bellaelysium)

    This was the first error before I add that line:
    Fatal error: Cannot redeclare penci_get_featured_image_size() (previously declared in /home3/bellaelysium/public_html/wp-content/themes/soledad/functions.php:1047)

    Thread Starter bellaelysium

    (@bellaelysium)

    I manage to get it to work…again adding that line (No idea why???)

    <?php
    /**
     * Plugin Name: Nelio Tweaks to Support Penci Theme
     * Version:     1.0.0
     *
     * Author:      Nelio Software
     * Author URI:  https://neliosoftware.com
     * License:     GPL-2.0+
     * License URI: https://www.gnu.org/licenses/gpl-2.0.txt
     *
     * @author     David Aguilera <[email protected]>
     * @since      1.0.0
     */
    
    // If this file is called directly, abort.
    if ( ! defined( 'WPINC' ) ) {
    	die;
    }
    if ( ! function_exists( 'penci_get_featured_image_size' ) ){
    function penci_get_featured_image_size( $id, $size = 'full' ) {
      // Nelio Tweak.
      if ( class_exists( 'Nelio_Content_External_Featured_Image_Helper' ) ) {
        $aux = Nelio_Content_External_Featured_Image_Helper::instance();
        $efi_url = $aux->get_nelio_featured_image( $id );
        if ( is_string( $efi_url ) && strlen( $efi_url ) ) {
          return $efi_url;
      }
    
      // Original function code.
      if ( ! has_post_thumbnail( $id ) ) {
        return '';
      } else {
        $image_html = get_the_post_thumbnail( $id, $size );
        preg_match( '@src="([^"]+)"@', $image_html, $match );
        $src = array_pop( $match );
        return $src;
      }
    }
    }
    }

    But hey, really so much thanks for making it work! A+ help there! ??

    Plugin Author David Aguilera

    (@davilera)

    Oops, I’m sorry, I see where the error is. Right after return $efi_url I missed a closing bracket:

    
    ...
      if ( is_string( $efi_url ) && strlen( $efi_url ) ) {
        return $efi_url;
      } // <-- this one was missing!!
    }
    ...
    

    so make sure to include it there and remove one at the end. Then, try to get rid of the if clause once again; I’m still surprised you need it.

    Thread Starter bellaelysium

    (@bellaelysium)

    Hello!

    Yes, I tried doing that too but it still doesn’t work!

    It gave this error:
    Fatal error: Cannot redeclare penci_get_featured_image_size()

    I am surprised too. No idea why though. Let me know if you figure that out as I am curious too!
    It still work when I add that missing bracket, together with the if clause.

    Hey..it works perfectly fine for now as I just checked everything. Thanks so much! ??

    • This reply was modified 7 years, 9 months ago by bellaelysium. Reason: good byes :)
    • This reply was modified 7 years, 9 months ago by bellaelysium.
Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Featured Images on thumbnails grey out’ is closed to new replies.