• wkwebsite

    (@wkwebsite)


    I used the GET-POST-IMAGE script by Tim McDaniels in the magazine mimbo themes.

    The scripts is to get the thumbnails like the following and it runs pretty well:
    <?php echo get_post_image (get_the_id(), ”, ”, ” .get_bloginfo(‘template_url’) .’/scripts/timthumb.php?zc=1&w=260&h=180&src=’); ?>

    BUT~! If i login as a contributor (non admin) after i submit a post n get approved, the posted image thumbnails doesnt show out!

    It is becoz the get_post_image plugins is working only if you upload images from WP administration area. I get this from “thumbnails for excerpt plugins”. Why i not using the thumbnails for excerpt is because of the limitation of the size of thumbnails.

    Anyway to fix this??
    And, i hope can find a wordpress user to be friend.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter wkwebsite

    (@wkwebsite)

    I hav tested the simple get thumbnails code in functions page

    function get_thumbnail() {
        $images = get_children('post_parent='.get_the_ID().'&amp;post_type=attachment&amp;post_mime_type=image');
        if ( $images ) {
            foreach( $images as $image_id => $image_infos ) {
                $the_image = wp_get_attachment_image_src( $image_id, 'thumbnail' );
                if ( $the_image ) {
                    print "<img src='$the_image[0]'/>";
                }
            }
        }else{
                    print "<img src='none.jpg'/>";
    	}
        return "";
    }

    It can get the thumbnails of uploaded images if the post is posted by admin in WP administration, but if i loggon as a contributor or author, the above thumbnails doesnt work n returns the none.jpg images.

    HOW? WHY? HELP~!!

    I need help with this too very badly! Does anyone know what is going on?

    Hi, it seems that when a author is adding an image a different img tag is generated then when a admin does this.
    The difference is the admin has a title=”{text}” tag, and a author has not.

    author generates:
    <img class=”alignnone size-medium wp-image-42″ src=”http://www.vragen.org/wp-content/uploads/2009/10/antwoorden-300×225.jpg&#8221; alt=”antwoorden” width=”300″ height=”225″ />

    admin generates:
    <img class=”alignnone size-medium wp-image-42″ title=”antwoorden” src=”http://www.vragen.org/wp-content/uploads/2009/10/antwoorden-300×225.jpg&#8221; alt=”antwoorden” width=”300″ height=”225″ />

    I’ve changed the function to the following

    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);
    			}
    			if(!$matches) {
    				preg_match("/<img class\=\".*\" 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;
    		 }
    	}
    }
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘get_post_image cannot show thumbnails for non admin user’ is closed to new replies.