如果没有附加图像,如何集成图像?
我使用这段代码成功地集成了没有图片的图片,如果没有图片附在帖子上。
<?php
if ( ! $img = get_field(\'img_actor\', $post_object->ID ) )
$img = \'/wp-content/uploads/noimage1.jpg\';
?>
<img class="actor_img" src="/scripts/timthumb.php?src=<?php echo urlencode($img); ?>&h=70&w=50&zc=1"
好吧,但我如何才能将此代码集成到我的GD星级代码中。Gd Star Rating是一个插件,用于对帖子进行评级-
GD Star Ratingforeach ($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";
}
}
完整代码的链接
https://github.com/MaineLearning/MaineLearning/blob/master/wp-content/plugins/gd-star-rating/code/t2/render.php如何添加页面以显示帖子数量。
<?php
wp_gdsr_render_rating_results(array(\'template_id\' => 48, \'rows\' => 1, \'select\' => \'persoane\', \'min_votes\' => 0, \'min_count\' => 0, \'excerpt_words\' => 0, \'image_from\' => \'custom\', \'image_custom\' => \'img_actor\', \'image_resize_x\' => 55, \'image_resize_y\' => 70, \'publish_days\' => 1, \'rating_size\' => \'12\', \'review_size\' => \'12\', \'rating_thumb_size\' => \'12\'));
?>
最合适的回答,由SO网友:Charles Clarkson 整理而成
更改此项:
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 ( \'custom\' == $widget[\'image_from\'] ) {
$post_custom_id = get_post_meta( $row->post_id, $widget[\'image_custom\'], true );
if ( get_post_meta( $post_custom_id, \'_wp_attached_file\', 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
$row->image = get_bloginfo(\'url\') . \'/scripts/timthumb.php?src=\' . get_bloginfo(\'url\') . \'/wp-content/uploads/noimage1.jpg&h=70&w=55&zc=1\';
}
SO网友:s_ha_dum
非常粗糙,但如果您想在以下情况下添加图像--get_post_meta($row->post_id, $widget["image_custom"], true);
-- 是空的,下面应该这样做。你需要改变test_meta
不管怎样$widget["image_custom"]
是
function alter_meta_wpse_106998($a, $object_id, $meta_key, $single) {
if (\'test_meta\' === $meta_key) {
$meta_type = \'post\';
$meta_cache = wp_cache_get($object_id, $meta_type . \'_meta\');
if ( !$meta_cache ) {
$meta_cache = update_meta_cache( $meta_type, array( $object_id ) );
$meta_cache = $meta_cache[$object_id];
}
if ( empty($meta_cache[$meta_key]) ) {
$meta_cache[$meta_key][] = site_url(\'/wp-content/uploads/noimage1.jpg\');
}
if ( !$meta_key ) {
return $meta_cache;
}
if ( isset($meta_cache[$meta_key]) ) {
if ( $single ) {
return maybe_unserialize( $meta_cache[$meta_key][0] );
} else {
return array_map(\'maybe_unserialize\', $meta_cache[$meta_key]);
}
}
if ($single) {
return \'\';
} else {
return array();
}
}
return null;
}
add_filter(\'get_post_metadata\',\'alter_meta_wpse_106998\',1,4);
如果您查看该代码,它在很大程度上是对
get_metadata
并大量借用了该功能。