Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a post with image gallery, it has 10 images. Can I get the direct link to the images in the post, so that I can display first 5 images on the homepage?

share|improve this question

3 Answers 3

You could use this loop for fetching the images from current post.

<?php
$images = get_posts(array(
    'post_parent' => get_the_ID(),
    'post_type' => 'attachment',
    'posts_per_page' => 5,
    'post_mime_type' => 'image'
));

if( $image ) {
    foreach($images as $image) :
        echo wp_get_attachment_link( $image->ID, 'thumbnail-size', true );
    endforeach;
}
?>

reference:

  1. wp_get_attachment_link
  2. wp_get_attachment_image
share|improve this answer

Add this to your child themes functions file and change the image I.D's to match the ones you want included in the gallery.

add_action( 'wp_head', 'wpsites_front_page_gallery' );
function wpsites_front_page_gallery() {
if ( is_home() ) {
echo do_shortcode('[gallery columns="5" link="file" ids="45266,45258,45250,45229,45227" orderby="rand"]');
}}

enter image description here

Change the wp_head hook to any WordPress or theme specific hook for positioning.

share|improve this answer

If you are using Next Gen Gallery you can then install an additional plugin which allows widgets http://wordpress.org/extend/plugins/nextgen-gallery-sidebar-widget/

If you are using WordPress own Image Library and Gallery function try this plugin http://wordpress.org/extend/plugins/fx-gallery-widget/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.