这段代码可以工作,尽管我怀疑它可能更高效,或者被更好的过滤器替代。我根据这个问题的答案修改了这段代码,这是我花了几个小时试用的所有googles中最好的选择。enter link description here
您需要将“full”更改为您想要的大小(在两个位置)。您还可以根据需要更改其他数组元素(在“提取”函数之后)。
我愿意用更简单/更有效的方法来做这件事。
function change_image_size ($output, $attr) {
global $post; // needed to use in the id element
extract(shortcode_atts(array(
\'order\' => \'ASC\',
\'orderby\' => \'menu_order ID\',
\'id\' => $post->ID,
\'itemtag\' => \'dl\',
\'icontag\' => \'dt\',
\'captiontag\' => \'dd\',
\'columns\' => 3,
\'size\' => \'thumbnail\',
\'include\' => \'\',
\'exclude\' => \'\'
), $attr));
// here\'s where you can change/add an attribute to the shortcode
$attr[\'size\'] = \'full\'; // change \'full\' to desired size
$id = intval($id);
if (\'RAND\' == $order) {
$orderby = \'none\';
}
if (!empty($include)) {
$include = preg_replace(\'/[^0-9,]+/\', \'\', $include);
$_attachments = get_posts(array(\'include\' => $include,
\'post_status\' => \'inherit\', \'post_type\' => \'attachment\',
\'post_mime_type\' => \'image\', \'order\' => $order,
\'orderby\' => $orderby));
$attachments = array();
foreach ($_attachments as $key => $val) {
$attachments[$val->ID] = $_attachments[$key];
}
} elseif (!empty($exclude)) {
$exclude = preg_replace(\'/[^0-9,]+/\', \'\', $exclude);
$attachments = get_children(array(\'post_parent\' => $id, \'exclude\' => $exclude, \'post_status\' => \'inherit\', \'post_type\' => \'attachment\', \'post_mime_type\' => \'image\', \'order\' => $order, \'orderby\' => $orderby));
} else {
$attachments = get_children(array(\'post_parent\' => $id,
\'post_status\' => \'inherit\', \'post_type\' => \'attachment\',
\'post_mime_type\' => \'image\', \'order\' => $order,
\'orderby\' => $orderby));
}
if (empty($attachments)) {
return \'\';
}
// Essentially these are only changes I\'ve made
// you can change the $output to your needs; including changing \'full\' to your desired image size.
$output = \'\';
foreach ($attachments as $att_id => $attachment) {
$output .= \'<figure>\' . wp_get_attachment_image($att_id, \'full\') .
\'<figcaption>\' . wptexturize($attachment->post_excerpt) .
\'</figcaption></figure>\';
} // change \'full\' to desired size
return $output;
}
add_filter(\'post_gallery\', \'change_image_size\', 10, 2);