Forums

How to show post attachments (skipping the first one!!) (2 posts)

  1. moodless
    Member
    Posted 1 year ago #

    Hello

    I found this code on the forum and it worked perfectly with me

    <?php
    
    $args = array(
    	'post_type' => 'attachment',
    	'numberposts' => null,
    	'post_status' => null,
    	'post_parent' => $post->ID
    );
    $attachments = get_posts($args);
    if ($attachments) {
    	foreach ($attachments as $attachment) {
    
    		the_attachment_link($attachment->ID, false);
    	}
    }
    
    ?>

    I understand it create an array to list all the attachments in the post , but how can i skip the first one..

    The thing is im trying to create a gallery of images beneath the post content, but i want to show the first one (in order) inside the content and list the rest under it

    Regards

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    Try using:

    $args = array(
        'post_type' => 'attachment',
        'numberposts' => null,
        'post_status' => null,
        'post_parent' => $post->ID'
        'offset' => 1
    );

Topic Closed

This topic has been closed to new replies.

About this Topic