最近,我一直在处理特色图片,并不断将它们添加到我的帖子中。然而,我有一堆没有特色图片集的老帖子,我想将其用于wptouch等。
所以我有300篇帖子,老实说,我不想进入300篇帖子,手动设置图片。
无论是通过插件还是代码,你都可以在特色图片区抓取每篇文章中的第一张图片的地方对其进行编码吗?
最近,我一直在处理特色图片,并不断将它们添加到我的帖子中。然而,我有一堆没有特色图片集的老帖子,我想将其用于wptouch等。
所以我有300篇帖子,老实说,我不想进入300篇帖子,手动设置图片。
无论是通过插件还是代码,你都可以在特色图片区抓取每篇文章中的第一张图片的地方对其进行编码吗?
如果将图像插入(附加)帖子而不是外部链接:
function get_my_thumbnail($post_id, $size, $attr = \'\'){
// check of featured image first
$t = get_post_thumbnail_id($post_id);
// no featured image set, check post attachments
if(empty($t)){
$attachments = get_children(array(
\'post_parent\' => $post_id,
\'post_status\' => \'inherit\',
\'post_type\' => \'attachment\',
\'post_mime_type\' => \'image\',
\'order\' => \'ASC\',
\'orderby\' => \'menu_order ID\',
));
$attachment = array_shift($attachments); // we only need one
$t = $attachment ? $attachment->ID : false;
}
// no attachments either...
if(empty($t)) return \'no image...\';
// we have either attachment / featured image, so output the post thumbnail
do_action(\'begin_fetch_post_thumbnail_html\', $post_id, $t, $size); // compat
$html = wp_get_attachment_image($t, $size, false, $attr);
do_action(\'end_fetch_post_thumbnail_html\', $post_id, $t, $size);
return $html;
}
您可能还想regenerate all attachment sizes (自动创建$size
-d图像),所以您不会在浏览器中调整大图像的大小。。。功能如下:
function catch_that_image() {
global $post, $posts;
$first_img = \'\';
ob_start();
ob_end_clean();
$output = preg_match_all(\'/<img.+src=[\\\'"]([^\\\'"]+)[\\\'"].*>/i\', $post->post_content, $matches);
$first_img = $matches [1] [0];
// no image found display default image instead
if(empty($first_img)){
$first_img = get_bloginfo(\'template_url\')."/images/no_image.gif";
}
return $first_img;
}
下面是如何使用它:$imgURL = catch_that_image();
我刚刚更改了博客的主题,由于页面宽度很小,它打破了布局。我之前的大多数图片(附在帖子中)的宽度都在600px左右,现在我需要按450px的比例调整它们的大小。如何一次性调整它们的大小?有这个插件吗?P、 美国:编写CSS规则是一个很好的选择,我已经做到了。但我认为调整图像大小也会减少每个页面的下载开销!