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.

709 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 :)

709 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
3437 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.

3437 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…

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by