当我需要显示附加到post gallery的缩略图时,我会在函数中使用自定义函数。php。对于你的需求来说,这可能是过分的,但它应该涵盖一切。
在本例中,我检索了帖子库中的所有图像,然后在列表项中显示每个图像。该列表包含包裹在锚定中的缩略图,该锚定链接到图像来自的帖子。可以根据您的需要轻松定制输出字符串。
function get_gallery_image_thumb_list($size){
global $post;
$args = array(
\'numberposts\' => null,
\'post_parent\' => $post->ID,
\'post_type\' => \'attachment\',
\'nopaging\' => false,
\'post_mime_type\' => \'image\',
\'order\' => \'ASC\',
\'orderby\' => \'menu_order ID\',
\'post_status\' => \'any\'
);
$attachments =& get_children($args);
if ($attachments) {
foreach($attachments as $attachment) {
foreach($attachment as $attachment_key => $attachment_value) {
$imageID = $attachment->ID;
$imageTitle = $attachment->post_title;
$imageCaption = $attachment->post_excerpt;
$imageDescription = $attachment->post_content;
$imageAlt = get_post_meta($imageID, \'_wp_attachment_image_alt\', true);
$imageArray = wp_get_attachment_image_src($attachment_value, $size, false);
$imageURI = $imageArray[0]; // 0 is the URI
$imageWidth = $imageArray[1]; // 1 is the width
$imageHeight = $imageArray[2]; // 2 is the height
// Build the <img> string
$ImgString = \'<li><a href="\' . get_permalink() . \'" title="\' . the_title("", "", false) . \'"><img src="\' . $imageURI . \'" width="\' . $imageWidth . \'" height="\' . $imageHeight . \'" alt="\' . $imageAlt . \'" title="\' . $imageTitle . \'" /></a></li>\';
// Print the image
echo $ImgString;
break;
}
}
}
unset($args);}
然后调用函数并传入要返回的图像大小(缩略图、中、大或全),如下所示:
get_gallery_image_thumb_list("thumbnail");
这需要在循环或自定义循环中调用。