我正在尝试从附件中排除多个帖子缩略图。
我的函数中设置了以下缩略图。php:
$thumb = new MultiPostThumbnails(array(
\'label\' => \'Client Logo\',
\'id\' => \'client-logo\',
\'post_type\' => \'clients\'
)
);
$thumb = new MultiPostThumbnails(array(
\'label\' => \'Portfolio Home Image\',
\'id\' => \'port-home-image\',
\'post_type\' => \'clients\'
)
);
$thumb = new MultiPostThumbnails(array(
\'label\' => \'Home Slide Image\',
\'id\' => \'home-slide-image\',
\'post_type\' => \'clients\'
)
);
然后,我在循环中得到了以下代码,以引入所有图像附件并对其进行分解
<?php
$thumb_id = get_post_thumbnail_id( $post_id );
$args = array(
\'post_type\' => \'attachment\',
\'numberposts\' => $nimg,
\'post_mime_type\' => \'image\',
\'post_status\' => null,
\'post_parent\' => $post->ID,
\'exclude\' => $thumb_id
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
//echo apply_filters(\'the_title\', $attachment->post_title);
echo wp_get_attachment_image( $attachment->ID, array (650,650));
}
}
?>
该行:
$thumb_id = get_post_thumbnail_id( $post_id );
排除特色帖子缩略图。
关于如何排除其他3个缩略图,有什么想法吗?
任何帮助都将不胜感激。
谢谢Danyo
http://wordpress.org/extend/plugins/multiple-post-thumbnails
SO网友:koskoz
我只修改了“排除”行。它没有经过测试,但应该可以工作。
<?php
$thumb_id = get_post_thumbnail_id( $post_id );
$args = array(
\'post_type\' => \'attachment\',
\'numberposts\' => $nimg,
\'post_mime_type\' => \'image\',
\'post_status\' => null,
\'post_parent\' => $post->ID,
\'exclude\' => $thumb_id, MultiPostThumbnails::get_post_thumbnail_id(\'clients\', \'client-logo\', $post_id), MultiPostThumbnails::get_post_thumbnail_id(\'clients\', \'port-home-image\', $post_id), MultiPostThumbnails::get_post_thumbnail_id(\'clients\', \'home-slide-image\', $post_id)
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
//echo apply_filters(\'the_title\', $attachment->post_title);
echo wp_get_attachment_image( $attachment->ID, array (650,650));
}
}
?>