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.
<?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_shortcodeitsmattadams said
<?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 
In that case, have a look at this:
http://digwp.com/2009/08/awesome-image-attachment-recipes-for-wordpressYou can also learn from this plugin:
http://wordpress.org/extend/plugins/slideshow
<?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
OrganicBeeMedia
This function doesn’t work for me.. when I place it in to my loop, it displays nothing
thx for your time.
Itachicz said
OrganicBeeMediaThis 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
OrganicBeeMedia said
Itachicz saidthats because its trying to pull my custom image sizes you’ll need to change it to fit your needs
OrganicBeeMediaThis function doesn’t work for me.. when I place it in to my loop, it displays nothing
thx for your time.
Even when I changed your image sizes to default values it doesn’t work…
