1

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?

3 Answers 3

2

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
1

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.

0

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/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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