仅显示当前图库中的内容

时间:2012-11-16 10:59:37

标签: wordpress

我想修改下面的脚本,以便发布/显示我当前固定链接库的内容 - 在当前阶段,虽然它显示了所有图库的所有图像。我怎么能改变这个?

        <?php 
        $wp_query = new WP_Query();
        $wp_query->query( array( 'post_type' => 'galleries', 'posts_per_page' => of_get_option('le_gallery_items'), 'paged' => $paged, 'orderby' => 'menu_order', 'order' => 'ASC') );
        $mod = 1;
        while ( $wp_query->have_posts() ) : $wp_query->the_post(); 
        $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order') );
        if(has_post_thumbnail()) {
            $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
            $src = $src[0];
        }
        else{
            foreach ( $attachments as $id => $attachment ) {
                $src = wp_get_attachment_url( $id );
            }
        }
         if ($mod % 3 == 0) {
            echo ' <div class="gallery-entry-img-last">';
         }
         else{
            echo ' <div class="gallery-entry-img">';
         }
         ?>

非常感谢一些专家的帮助。

1 个答案:

答案 0 :(得分:1)

如果您只想获取当前页面的所有图像,请使用此代码

if ( $images = get_posts(array(
   'post_parent' => $post->ID,
   'post_type' => 'attachment',
   'numberposts' => -1,
   'post_mime_type' => 'image',)))
{
 foreach( $images as $image ) {
 $attachmenturl=wp_get_attachment_url($image->ID);
 $attachmentimage=wp_get_attachment_image_src( $image->ID, full );
 $imageDescription = apply_filters( 'the_description' , $image->post_content );
 $imageTitle = apply_filters( 'the_title' , $image->post_title );

 //echoing the attachment  
 echo '<img src="' . $attachmentimage[0] . '" alt="" />';
 }
}     
else {
     echo "No Image";
}

//to exclude feature image use this
get_post_thumbnail_id( $post->ID );
$thumb_ID = get_post_thumbnail_id( $post->ID );

if ( $images = get_posts(array(
    'post_parent' => $post->ID,
    'post_type' => 'attachment',
    'numberposts' => -1,
    'post_mime_type' => 'image',
    'exclude' => $thumb_ID))) //exluding feature image by its ID
相关问题