0

我想修改以下脚本以发布/显示我当前永久链接的画廊的内容 - 尽管它显示所有画廊的所有图像,但在当前阶段。我怎样才能改变这个?

        <?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">';
         }
         ?>

一些专家的帮助将不胜感激。

4

1 回答 1

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
于 2012-11-16T11:39:37.053 回答