I hav tested the simple get thumbnails code in functions page
function get_thumbnail() {
$images = get_children('post_parent='.get_the_ID().'&post_type=attachment&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” 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” 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;
}
}
}