WordPress.org

Forums

Gallery post format; more than one image (11 posts)

  1. ivan2704
    Member
    Posted 3 years ago #

    Hi all, first Merry Christmas :). Second, I have question. I would like to have more than one image (let say 3 images) on the excerpt of gallery post. In twentyten theme I found this piece code that outputs one image

    <?php
    $images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
    if ( $images ) :
    $total_images = count( $images );
    $image = array_shift( $images );
    $image_img_tag = wp_get_attachment_image( $image->ID, 'thumbnail' );
    ?>
    (there is more...)
    But how tu output 3 images? Thank you

  2. Pavan
    Member
    Posted 3 years ago #

    try to use this...
    'posts_per_page' => 3

    this will show 3 images to post. u can change the number according to ur need.

  3. ivan2704
    Member
    Posted 3 years ago #

    This solution just shows 3 image in gallery. I want to be able to put 3 images on the excerpt page if you know what I mean

  4. Pavan
    Member
    Posted 3 years ago #

    can u explain what exactly are u saying?

  5. ivan2704
    Member
    Posted 3 years ago #

    Here is image to explain. Now I have like this, and I want to have 3 images instead this one

  6. Pavan
    Member
    Posted 3 years ago #

    is it a post ?

    if it is, then do u want three posts like this?

  7. ivan2704
    Member
    Posted 3 years ago #

    Here, I think this image explains it

  8. Pavan
    Member
    Posted 3 years ago #

    ok, i understood what u want.....
    you have to wait for some time bro.......

  9. Pavan
    Member
    Posted 3 years ago #

    these are images uploaded in posts or page?

  10. ivan2704
    Member
    Posted 3 years ago #

    images are in post in gallery

  11. Pavan
    Member
    Posted 3 years ago #

    If images are in post then use this code..

    <?php
    $args = array( 'post_type' => 'attachment', 'numberposts' => -1,'post_status' => null,'post_parent' =>$post->ID,'posts_per_page'=>3);
    						 $attachments=get_posts($args);
     if ( $attachments ){
    	?>
        <ul>
    <?php
       foreach ( $attachments as $attachment ){
          $img = wp_get_attachment_image_src($attachment->ID, 'large');?>
    	<li>
    	<img src="<?php echo $img[0]; ?>" alt='' width="598" height="400"/>
    	</li>
    <?php	}?>
        </ul>
    <?php	} ?>

    It will surely print only three images from your attachment..

    after that apply your stylesheet to look like yours

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.