Fred K
Fred K

Reputation: 13910

Show images from Wordpress 3.5 gallery

First I create a gallery in a post (using the built-in Wordpress gallery).

Now, since I don't like how Wordpress shows the gallery (in the frontend), in the single.php page I want to retrieve the image IDs of that gallery, because I want to create a customized gallery using php code and a plugin like FancyBox.

I've tried many codes but no one works! I'm using Wordpress 3.5.1 with Bootstrap.

Upvotes: 0

Views: 310

Answers (2)

David Chase
David Chase

Reputation: 2073

You can take a look post/page gallery tip here.

It does more or less exactly what you are looking for and you can expand on the options.

Upvotes: 0

Banago
Banago

Reputation: 1420

Here it is how you do a custom gallery with the images attached to a post/page in WordPress. This is true about for WP 3.5 and older versions too.

<ul>
<?php $images = get_children('post_type=attachment&post_mime_type=image&post_parent=' . $post->ID . ' &orderby=menu_order&order=ASC');
foreach( $images as $img_id => $img_r ) :
     $thumb = wp_get_attachment_image_src( $img_id, 'thumb', true );
     $full = wp_get_attachment_image_src( $img_id, 'full', true ); ?>
     <li>
        <a href="<?php echo $full[0] ?>">
             <img src="<?php echo $thumb[0] ?>" alt="<?php echo get_the_title( $img_id ) ?>" title="<?php echo get_the_title( $img_id ) ?>">
        </a>
     </li>

<?php endforeach; ?>
</ul>

Add CSS classes to the HTML to fit your needs.

Upvotes: 0

Related Questions