I've found a way to insert a customized gallery inside my wordpress template but I'm not sure this is the better way.

I've uploaded my images with the default image uploader of wordpress to manage the photos, than I've removed it from the post article and managed the media from the loop-single.php page template I've created like this:

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>


<script type="text/javascript">
    /* gallery */

    var params = {
    var gallery = new ImgGalleryManager ('#site-gallery', '#gallery-menu', 'selected', params);

    /* */

$args = array(
    'order'          => 'ASC',
    'post_type'      => 'attachment',
    'post_parent'    => $post->ID,
    'post_mime_type' => 'image',
    'post_status'    => null,
    'numberposts'    => -1,
$attachments = get_posts($args);
if ($attachments) {
    $html = '<div id="site-gallery">

    foreach ($attachments as $attachment) {
        //echo apply_filters('the_title', $attachment->post_title);
        $html .= '<td>'. wp_get_attachment_link($attachment->ID, 'full', false, false).'</td>';
        if (empty($list_imgs)) {
            $list_imgs = '<div id="gallery-menu"><div class="img-selector selected"></div>';
        } else {
            $list_imgs .= '<div class="img-selector"></div>';

    $html .= '</tr>

    echo $html;
<div id="cnt-title"><?php the_title(); ?></div>
<div id="post-content">
    <?php the_content(); ?>
    <?php the_tags(); ?>

<?php endwhile; // end of the loop. ?>

I can't believe this is the best way to manage photos but I don't know wordpress and I've did the first thing I thought.

Should I use a better way to custom the image gallery of a post or is this the best way?

Is it possible to customize the [gallery] in the loop-single.php page without remove it and create it manually?

I've read here how to customize the gallery, but if I do it I'll print the customized gallery, and than with <?php the_content(); ?> I'll print it again with the default wordpress style.

Does exists some way to customize [gallery] directly?

1 Answer 1


I'm good with everything except for the removed it from the post article part. Leaving the images attached to the Post actually makes it easier to work with the images, because you can query them by post_parent.

Also: what do you mean by managed the media from the post-template.php? Are you saying that you modified the core post-template.php file?

  • Sorry the right name is loop-single.php, I've created this in the theme/theme_name/ folder. I've tried to leave the gallery but if I leave it in the post form It's printed as the default wordpress gallery. As you see I manually get the media from $attachments = get_posts($args); and with a foreach statement and I print the gallery independently. So If I leave the original gallery I see the gallery twice, the default version and the customized one. How can I cutomize the default gallery?
    – vitto
    May 13, 2011 at 20:48
  • If you don't want to output the Gallery as per the default, then simply don't add the [gallery] shortcode to the Post. Alternately, you can filter the [gallery] shortcode, to query and output exactly as you want it to. May 14, 2011 at 21:05
  • filter the gallery, that's what I needed!
    – vitto
    May 15, 2011 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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