如果只有一个,如何不打印缩略图? WordPress的
How to don't print thumbnail image if it is only one? WORDPRESS
我在 single.php:
中使用代码
<?php echo show_all_thumbs(); ?>
打印我所有的 post 缩略图。
只有一张缩略图如何不打印?如何检查:如果只有一张图片,什么都不做......?
我的functions.php:
function show_all_thumbs() {
global $post;
$post = get_post($post);
/* image code */
$images = &get_children( 'post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent='.$post->ID);
if ($images) {
foreach ($images as $imageID => $imagePost) {
unset($the_b_img);
$src = wp_get_attachment_image_src($imageID, false);
$the_b_img = wp_get_attachment_image($imageID, 'thumbnail', false);
$thumblist .= '<a class="gallery_colorbox cboxElement" href="'. $src[0] .'">'.$the_b_img.'</a>';
}
}
return $thumblist;
}
可以用count
函数查看图片数量:replace
if ($images) {
和
if (count($images) > 1) {
我在 single.php:
中使用代码<?php echo show_all_thumbs(); ?>
打印我所有的 post 缩略图。
只有一张缩略图如何不打印?如何检查:如果只有一张图片,什么都不做......?
我的functions.php:
function show_all_thumbs() {
global $post;
$post = get_post($post);
/* image code */
$images = &get_children( 'post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent='.$post->ID);
if ($images) {
foreach ($images as $imageID => $imagePost) {
unset($the_b_img);
$src = wp_get_attachment_image_src($imageID, false);
$the_b_img = wp_get_attachment_image($imageID, 'thumbnail', false);
$thumblist .= '<a class="gallery_colorbox cboxElement" href="'. $src[0] .'">'.$the_b_img.'</a>';
}
}
return $thumblist;
}
可以用count
函数查看图片数量:replace
if ($images) {
和
if (count($images) > 1) {