Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

The title is the short version of the question. Here's what I need in more details...

If the answer is not so simple, I would be glad if you can point me to the right direction with a tutorial or to the codex and where I can ready more about this.

Inside the WP loop, and "maybe" before using "the_content();", how can I tell wordpress to go to the database, loop/query through each one of the images inserted on that post/page, in such a way that I'll have full control of how those images will be displayed.

I need something that will be easy and intuitive for the client to update (with new images), and I consider easy and intuitive when you only have to click the "add media" button, upload some images and add them to the post/page.

At the same time, I need more control on how those images will be displayed to show all them like so:

<a href="link-to-full-img-size-01"><img href="img-01-thumbnail" /></a>
<a href="link-to-full-img-size-02"><img href="img-02-thumbnail" /></a>
<a href="link-to-full-img-size-03"><img href="img-03-thumbnail" /></a>
<a href="link-to-full-img-size-04"><img href="img-04-thumbnail" /></a>

And each anchor link will also have a rel="shadowbox[page-title]".

I've done this before, and something even more complex than this, but it's far from being easy to maintain (at least for clients).

I'm thinking about creating a custom-post-type with some different taxonomies. Then I create a new post, linked to a given taxonomy, use it as a bucket for all the images for that taxonomy, and than import it all inside another page-template, but I still don't know how to control how the images will be displayed.

Hope the question and description is clear enough. Thanks!

share|improve this question
    
This question has been asked a lot, wordpress.stackexchange.com/search?q=image_send_to_editor –  Wyck Feb 2 '13 at 20:26
    
Thanks. I'll check some of those. I did some searching before posting but I didn't know about the image_send_to_editor. Thanks again! –  7th Feb 2 '13 at 20:28

2 Answers 2

You can overwrite the default gallery shortcode.

This might help you in the right direction:

http://hasin.me/2013/02/04/overriding-default-gallery-shortcode-and-fetch-the-attachments-easily/

share|improve this answer
    
Thanks birgire but I was not using a shortcode, and didn't even want to use the WP gallery as it is, but you're link was helpful in using/setting the custom sizes I needed. I'll post the solution that worked for me. –  7th Feb 4 '13 at 4:54
1  
ok good it worked out for you, even though you didn't want to use shortcode + WP gallery ;-) –  birgire Feb 4 '13 at 8:59
    
Dead link is dead –  Howdy_McGee Nov 6 '13 at 20:05
    
Thanks, I'm not happy either with my link answer, it was one of my very first answer here on WPSE ;-) This is a good lesson in why link-only-answers are no good ;-) –  birgire Nov 12 '13 at 10:13
up vote 0 down vote accepted

After some research, I came up with a solution that worked for me.

It's nice because it's not using the WP Gallery (you don't need to insert a gallery into your post/page to make it work).

It's awesome because you can do whatever you want inside the "images loop".

Note: the 'preview' in $size='preview' is a custom size I created using add_image_size( 'preview', 120, 120, true ); inside my functions.php file.

And here's what I came up with:

(... inside a new page.php ...)

<?php do_atomic( 'open_content' ); ?>
<?php $imgs_args = array(
        'numberposts'   => -1,
        'order'         => 'DESC',
        'post_mime_type'=> 'image',
        'post_type'     => 'attachment',
        'post_parent'   => $post->ID,
      ); $imgs = get_children( $imgs_args ); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

(...)

<?php the_content(); ?>
<?php if( $imgs ) : ?>
    <div class="showcase">
    <?php foreach( $imgs as $img ) : ?>
    <?php /* Setting Sizes */
        $preview_size = wp_get_attachment_image_src( $img->ID, $size='preview' );
        $full_size = wp_get_attachment_image_src( $img->ID, $size='full-size' ); ?>
        <a href="<?php echo $full_size[0]; ?>" rel="shadowbox" alt="<?php echo $img->post_title; ?>">
            <img src="<?php echo $preview_size[0]; ?>" alt="<?php echo $img->post_title; ?>" />
        </a>
    <?php endforeach; ?>
    </div>
<?php endif; ?>

(...)

It's also worth mentioning that Justin Tadlock has a really nice plugin called Cleaner Gallery. It was while checking his plugin' code that I found out about the nice get_children(); function that makes all this customization possible.

Hope it helps someone else in the future.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.