• Hello, I’m trying to put together a somewhat portfolio site and I was wondering if there is a way or some code hack to get a certain number of the latest images you upload in the media section to appear on the home page (which at this stage I’ll make the home page a static page from a template so thats why i’m asking for the code mainly to do it)

    I had a look at Nextgen gallery, don’t really like it cause it generates invalid code, and I’m pretty happy with the default gallery wordpress has. I also tries out YD Recent Images but it displayed it all messy.

    Any help/suggestions would be appreciated thanks 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    To get the latest 2 uploaded images:

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

    change 'posts_per_page' => 2 to have more or less images.

    Thread Starter ichabod1799

    (@ichabod1799)

    do i just change the 2 in “posts_per_page’ => 2” to another number? such as 9?

    Moderator keesiemeijer

    (@keesiemeijer)

    do i just change the 2 in “posts_per_page’ => 2” to another number? such as 9?

    Yes. posts_per_page' => 9 if you want nine images to show.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Code for Latest Images’ is closed to new replies.