我已经尝试了一周多的时间来验证代码检索到的4个图像GD Star Rating plugin
这是我的代码:
wp_gdsr_render_rating_results(array(\'template_id\' => 49, \'rows\' => 4, \'select\' => \'post\', \'hide_empty\' => false, \'min_votes\' => 0, \'min_count\' => 0, \'excerpt_words\' => 0, \'image_from\' => \'custom\', \'image_custom\' => \'img\', \'image_resize_x\' => 72, \'image_resize_y\' => 80, ));
所以输出如下:
我在谷歌上搜索,修改代码,通过自定义字段获取海报。
我添加它是为了从自定义字段中检索图片。
foreach ($all_rows as $row) {
if ($widget["image_from"] == "content") {
$row->image = gdFunctionsGDSR::get_image_from_text($row->post_content);
} else if ($widget["image_from"] == "custom") {
$post_custom_id = get_post_meta($row->post_id, $widget["image_custom"], true);
$row->image = get_bloginfo(\'url\')."/scripts/timthumb.php?src=".get_bloginfo(\'url\')."/wp-content/uploads/".get_post_meta($post_custom_id,"_wp_attached_file",true)."&h=70&w=55&zc=1";
}
else if ($widget["image_from"] == "trailer") {
$post_custom_id = get_post_meta($row->post_id, $widget["image_trailer"], true);// getVideoId is a custom function
$row->image ="http://img.youtube.com/vi/".$post_custom_id ."/0.jpg" ;
} else $row->image = "";
$row->image = apply_filters(\'gdsr_widget_image_url_prepare\', $row->image, $widget, $row);
if ($row->image != "" && intval($widget["image_resize_x"]) > 0 && intval($widget["image_resize_y"]) > 0) {
$row->image = GDSRRenderT2::prepare_image($row->image, $widget["image_resize_x"], $widget["image_resize_y"]);
}
注:
这是原始代码行139
http://code.google.com/p/gd-star-rating/source/browse/trunk/code/t2/render.php?r=1041
我添加的代码是:
$row->image = get_bloginfo(\'url\')."/scripts/timthumb.php?src=".get_bloginfo(\'url\')."/wp-content/uploads/".get_post_meta($post_custom_id,"_wp_attached_file",true)."&h=70&w=55&zc=1";
}
因此,问题是如何将alt属性添加到要在html页面中显示的图像中。
我遇到的错误http://validator.w3.org 是
Line 580, Column 195: An img element must have an alt attribute, except under certain conditions. For details, consult guidance on providing text alternatives for images.
…tent/uploads/Battleship_1333017069_2012.jpg&h=70&w=55&zc=1"/></div>
SO网友:Charles Clarkson
将属性添加到创建img标记的每一行代码中。在文本编辑器中,搜索包含字符串的行"<img"
.
第241行和第273行:
$row->item_trend_rating = sprintf(\'<img class="trend" src="%s" style="%s" width="%s" height="%s"></img>\', $gdsr->e, $image_bg, $set_rating->size, $set_rating->size);
成为:
$row->item_trend_rating = sprintf(\'<img class="trend" src="%s" style="%s" width="%s" height="%s" alt="%s"></img>\', $gdsr->e, $image_bg, $set_rating->size, $set_rating->size, \'ALT TEXT HERE\' );
将此处的ALT TEXT更改为要在此处使用的文本。
第503行:
$rater_stars = \'<img src="\'.STARRATING_URL.sprintf("gfx.php?type=thumbs&value=%s", $score).\'" />\';
成为:
$rater_stars = \'<img src="\'.STARRATING_URL.sprintf("gfx.php?type=thumbs&value=%s", $score) . \'" alt="\' . $score . \'" />\';
第506行和第511行:
$rater_stars = \'<img src="\'.STARRATING_URL.sprintf("gfx.php?value=%s", $rating).\'" />\';
成为:
$rater_stars = \'<img src="\'.STARRATING_URL.sprintf("gfx.php?value=%s", $rating) . \'" alt="\' . $rating . \'" />\';
我使用$rating作为alt文本,因为它看起来像一个字符串。请随意更改。