148 posts
  • 3 Years of Membership
  • Czech Republic
  • Exclusive Author
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
  • Affiliate Level 2
  • Author Level 5
  • Beta Tester
  • Collector Level 2
+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
  • 3 Years of Membership
  • Czech Republic
  • Exclusive Author
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
  • Affiliate Level 2
  • Author Level 5
  • Beta Tester
  • Collector Level 2
+2 more
ChillThemes
says
3439 posts
  • Author Level 4
  • Collector Level 2
  • Community Superstar
  • United States
+2 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
  • 3 Years of Membership
  • Czech Republic
  • Exclusive Author
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.

3439 posts
  • Author Level 4
  • Collector Level 2
  • Community Superstar
  • United States
+2 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
  • 3 Years of Membership
  • Czech Republic
  • Exclusive Author
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