[英]Wordpress: Exclude the post thumbnail?
I am using the code below to get the attached images for each post in my theme for use in a slideshow. 我正在使用下面的代码来获取主题中每个帖子的附件图像,以便在幻灯片中使用。 It works great in that it is able to retrieve all of the attached images, but it also includes the post thumbnail .
它能够检索所有附加的图像,但效果很好,但它还包含post缩略图 。
So my question is, is there a way to exclude just the featured_image
but display the rest of the images? 所以我的问题是,有没有一种方法可以只排除
featured_image
但显示其余图像?
PHP 的PHP
function bdw_get_images($postId) {
$iPostID = $postId;
$arrImages =& get_children('post_type=attachment&post_mime_type=image&post_parent=' . $iPostID );
if($arrImages) {
$arrKeys = array_keys($arrImages);
foreach($arrImages as $oImage) {
$arrNewImages[] = $oImage;
}
for($i = 0; $i < sizeof($arrNewImages) - 1; $i++) {
for($j = 0; $j < sizeof($arrNewImages) - 1; $j++) {
if((int)$arrNewImages[$j]->menu_order > (int)$arrNewImages[$j + 1]->menu_order) {
$oTemp = $arrNewImages[$j];
$arrNewImages[$j] = $arrNewImages[$j + 1];
$arrNewImages[$j + 1] = $oTemp;
}
}
}
$arrKeys = array();
foreach($arrNewImages as $oNewImage) {
$arrKeys[] = $oNewImage->ID;
}
$iNum = $arrKeys[0];
foreach( $arrKeys as $key) {
$sImageUrl = wp_get_attachment_url($key);
$sImgString = '<img src="' . $sImageUrl . '" alt="Thumbnail Image" />';
echo $sImgString;
}
}
}
bdw_get_images($post->ID);
Get post thumbnail(if any) by get_post_thumbnail_id( $post_id ) function and check against it in the last loop. 通过get_post_thumbnail_id($ post_id)函数获取帖子缩略图(如果有),并在最后一个循环中对其进行检查。 So the last loop should look like this:
因此,最后一个循环应如下所示:
$post_thumbnail_id = get_post_thumbnail_id( $iPostID );
foreach( $arrKeys as $key) {
if( $key == $post_thumbnail_id )
continue;
$sImageUrl = wp_get_attachment_url($key);
$sImgString = '<img src="' . $sImageUrl . '" alt="Thumbnail Image" />';
echo $sImgString;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.