148 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Czech Republic
  • Sells items exclusively on Envato Market
Itachicz says

Hi,

I have simple wordpress gallery in post and now I want to get images (url’s) from this gallery in my index.php.

Does anyone know how to do it? I searched all over the web, but nothing…

thx for your time.

707 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+2 more
ChillThemes says
 <?php
    $gallery_shortcode = '[gallery id="' . intval( $post->post_parent ) . '"]';
    print apply_filters( 'the_content', $gallery_shortcode );
 ?>

Or, not tested but should work.

<?php
    $gallery = do_shortcode( sprintf( '[gallery id="%1$s" columns="5" numberposts="16" orderby="rand"]', $post->post_parent ) );
    if ( !empty( $gallery ) )
        echo $gallery;
?>
http://codex.wordpress.org/Using_the_gallery_shortcode
148 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Czech Republic
  • Sells items exclusively on Envato Market
Itachicz says

 <?php
    $gallery_shortcode = '[gallery id="' . intval( $post->post_parent ) . '"]';
    print apply_filters( 'the_content', $gallery_shortcode );
 ?>

Or, not tested but should work.

<?php
    $gallery = do_shortcode( sprintf( '[gallery id="%1$s" columns="5" numberposts="16" orderby="rand"]', $post->post_parent ) );
    if ( !empty( $gallery ) )
        echo $gallery;
?>
http://codex.wordpress.org/Using_the_gallery_shortcode

First of all thx for your post :)

yes this works for displaying styled gallery but I need images url, because I want use them in a slider :)

707 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+2 more
ChillThemes says
3343 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says
<?php //Get the Image attachment stuff
$args = array(
        'post_type' => 'attachment',
        'numberposts' => null,
        'post_status' => null,
        'post_mime_type' => 'image',
        'order'          => 'ASC',
        'post_parent' => $post->ID,
        'posts_per_page'    => '9999'
    );

$attachments = get_posts( $args ); ?>

<!-- Start Post <?php the_ID(); ?> -->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>    

     <?php if(count( $attachments ) > 1) { ?>

         <div class="flexslider">

            <ul class="slides">

            <?php foreach ( $attachments as $attachment ) {     

                $image_url =  wp_get_attachment_image_src($attachment->ID, 'cw-original' ); ?>

                <li>

                    <a href="<?php echo $image_url[0]; ?>" rel="prettyPhoto[pp_gal]"><?php echo wp_get_attachment_image( $attachment->ID, 'cw-gallery' ); ?></a>

                    <?php echo($attachment->post_excerpt);?>

                </li>

            <?php } ?>

            </ul>
        </div>
    <?php }//endif ?>
</article>

you still need to add the content etc… also remember that the gallery shortcode can still be inserted into post, you can strip them/hide but depending on if its for personal or a commercial theme thered be a different approach

148 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Czech Republic
  • Sells items exclusively on Envato Market
Itachicz says

OrganicBeeMedia

This function doesn’t work for me.. when I place it in to my loop, it displays nothing

thx for your time.

3343 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says

OrganicBeeMedia

This function doesn’t work for me.. when I place it in to my loop, it displays nothing

thx for your time.

thats because its trying to pull my custom image sizes you’ll need to change it to fit your needs

148 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Czech Republic
  • Sells items exclusively on Envato Market
Itachicz says


OrganicBeeMedia

This function doesn’t work for me.. when I place it in to my loop, it displays nothing

thx for your time.
thats because its trying to pull my custom image sizes you’ll need to change it to fit your needs

Even when I changed your image sizes to default values it doesn’t work…

by
by
by
by
by
by