我正在做一个WordPress主题,但有一件事我卡住了。正如你所知,WordPress中的post格式有不同类型的格式,除了gallery幻灯片之外,我做了所有类型的格式。我所需要的,例如,我创建了一篇新帖子,并将图片库添加到此帖子,然后我选择了一个帖子格式的库。问题是,图库显示了WordPress中包含的所有图像,但我只想显示post图像。
Code:
if ( ! function_exists( \'flexi_gallery_slideshow\' ) ) :
/**
* Display an optional post images. slideshow
*
*/
function flexi_gallery_slideshow( ){
echo \'<ul class="bxslider" >\';
$args = array(
\'post_parent\' =>$post->ID,
\'post_type\' => \'attachment\',
\'orderby\' => \'menu_order\', // you can also sort images by date or be name
\'order\' => \'ASC\',
\'numberposts\' => 3, // number of. images (slides)
\'post_mime_type\' => \'image\'
);
if ( $images = get_children( $args ) ) {
foreach( $images as $image ) {
echo \'<li>\';
echo wp_get_attachment_image($image->ID, array(\'640\', \'400\') );
echo \'</li>\';
}
}
echo \'</ul>\';
}
endif;
最合适的回答,由SO网友:ahmad araj 整理而成
我用功能get\\u post\\u gallery解决了这个问题
找到答案
if ( ! function_exists( \'flexi_gallery_slideshow\' ) ) :
/**
* Display an optional post read more link
*
*/
function flexi_gallery_slideshow( ) {
echo \'<ul class="bxslider">\';
if ( get_post_gallery() ) :
$gallery = get_post_gallery( get_the_ID(), false );
/* Loop through all the image and output them one by one */
foreach( $gallery[\'src\'] as $src ) : ?>
<li> <img src="<?php echo $src; ?>" class="gallery-slider" alt="Gallery image" /> </li>
<?php
endforeach;
endif;
echo \'</ul>\' ;
}
endif;