WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] EMERGENCY! I need help! (6 posts)

  1. Devotion
    Member
    Posted 3 years ago #

    Not sure what have happend, but, all of a sudden I get this:

    Fatal error: Call to undefined function get_post_image() in /home/lxmbrg/public_html/mag/wp-content/themes/deadline/includes/home-block-one.php on line 20

    It's been working fine since day one but now, all of a suddan, it doesn't work. Since like two hours ago.

    The call that error message is referring to is this:

    <?php echo get_post_image (get_the_id(), '', '', '' .get_bloginfo('template_directory') .'/timthumb.php?zc=1&w=300&h=100&src='); ?>

    ...which has been working fine, until now. :S

    I've deactivated all plugins and my theme - which didn't do anything.

    Any suggestions what it might be?

  2. Devotion
    Member
    Posted 3 years ago #

    I also get this where I've added that code to a php or text widget:

    Fatal error: Call to undefined function get_post_image() in /home/lxmbrg/public_html/mag/wp-content/plugins/php-code-widget/execphp.php(44) : eval()'d code on line 5

    Been working fine until now...

  3. Devotion
    Member
    Posted 3 years ago #

    Can't be TimThumb playing games since this piece of code DOES work:

    <img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=http://www.devotionmagazine.se/bylines/<?php the_author_meta('user_nicename'); ?>.jpg&h=90&w=80&zc=1&q=100" alt="<?php the_title(); ?>" alt="<?php the_author_meta('display_name'); ?>" align="left" class="entry_author_image" />

  4. Devotion
    Member
    Posted 3 years ago #

    If I change it to this:

    <?php echo get_the_post_thumbnail (get_the_id(), '', '', '' .get_bloginfo('template_directory') .'scripts/timthumb.php?zc=1&w=300&h=100&src='); ?>

    where I've changed get_post_image to get_the_post_thumbnail it does fetch the image - but not resizing according to the settings in the code setup.

    So, there's something wrong with the get_post_image call. But what?! Been working for years this setup, lol, until a few hours ago.

  5. Devotion
    Member
    Posted 3 years ago #

    Solved!

  6. Devotion
    Member
    Posted 3 years ago #

    Oh, wait, I forgot to add - this is how I solved it. I "simply" added this to my themes functions.php:

    function get_post_image ($post_id=0, $width=0, $height=0, $img_script='') {
    	global $wpdb;
    	if($post_id > 0) {
    
    		 // select the post content from the db
    
    		 $sql = 'SELECT post_content FROM ' . $wpdb->posts . ' WHERE id = ' . $wpdb->escape($post_id);
    		 $row = $wpdb->get_row($sql);
    		 $the_content = $row->post_content;
    		 if(strlen($the_content)) {
    
    			  // use regex to find the src of the image
    
    			preg_match("/<img src\=('|\")(.*)('|\") .*( |)\/>/", $the_content, $matches);
    			if(!$matches) {
    				preg_match("/<img class\=\".*\" title\=\".*\" src\=('|\")(.*)('|\") .*( |)\/>/U", $the_content, $matches);
    			}
    			$the_image = '';
    			$the_image_src = $matches[2];
    			$frags = preg_split("/(\"|')/", $the_image_src);
    			if(count($frags)) {
    				$the_image_src = $frags[0];
    			}
    
    			  // if src found, then create a new img tag
    
    			  if(strlen($the_image_src)) {
    				   if(strlen($img_script)) {
    
    					    // if the src starts with http/https, then strip out server name
    
    					    if(preg_match("/^(http(|s):\/\/)/", $the_image_src)) {
    						     $the_image_src = preg_replace("/^(http(|s):\/\/)/", '', $the_image_src);
    						     $frags = split("\/", $the_image_src);
    						     array_shift($frags);
    						     $the_image_src = '/' . join("/", $frags);
    					    }
    					    $the_image = '<img alt="" src="' . $img_script . $the_image_src . '" />';
    				   }
    				   else {
    					    $the_image = '<img alt="" src="' . $the_image_src . '" width="' . $width . '" height="' . $height . '" />';
    				   }
    			  }
    			  return $the_image;
    		 }
    	}
    }

Topic Closed

This topic has been closed to new replies.

About this Topic