Title: [Plugin: Attachments] cleaner code   indexing
Last modified: August 19, 2016

---

# [Plugin: Attachments] cleaner code indexing

 *  [stefsegers](https://wordpress.org/support/users/stefsegers/)
 * (@stefsegers)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-attachments-cleaner-code-indexing/)
 * Hi all,
 * finally found a gallery plugin that outputs exactly what I want.
 * [%INDEX%<img src=”%THUMBNAILPATH%” alt=”%IMAGETITLE%” title=”%IMAGEDESCRIPTION%” />](https://wordpress.org/support/topic/plugin-attachments-cleaner-code-indexing/void(0)?output_format=md)
 * The exact code I used in a page template is:
 *     ```
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
       <?php $attachments = attachments_get_attachments(); ?>
         <?php
           $attachments = attachments_get_attachments();
           $total_attachments = count($attachments);
         ?>
         <?php if( $total_attachments > 0 ) : ?>
             <?php for ($i=0; $i < $total_attachments; $i++) : ?>
   
             <a href="javascript:void(0)"><?=$attachments[$i]['id']?><img src="<?=$attachments[$i]['location']?>" alt="<?=$attachments[$i]['title']?>" title="<?=$attachments[$i]['caption']?>" /></a>
   
             <?php endfor ?>
         <?php endif ?>
       </div>
       <?php endwhile; endif; ?>
       ```
   
 * Problem 1: The output has a lot of line breaks and gives no clean code
    Here’s
   the output:
 *     ```
       <a href="javascript:void(0)">
       														925													<img src="http://www.trouwshoot.nl/wp-content/uploads/Myk-en-Tamara-3340.jpg" alt="foto 1" title="captions 1" /></a>
   
             <a href="javascript:void(0)">
       														924													<img src="http://www.trouwshoot.nl/wp-content/uploads/Bruiloft-Denis-en-Patricia-38611.jpg" alt="foto 2" title="captions 2" /></a>
   
             <a href="javascript:void(0)">
       														923													<img src="http://www.trouwshoot.nl/wp-content/uploads/Bianca_Melvin-2973.jpg" alt="foto 3 " title="caption 3" /></a>
   
               </div>
       ```
   
 * My second problem is that the ID’s have a large number. For me the best thing
   would be if all pictures could be indexed. So instead of ID=923 you will get 
   INDEX=1
 * The 3rd problem is that I can add as much images I want, but after 20 images 
   my screen gets full and I need a >>> link to a next page with images 21 till 
   40. So paging all links would be great.
 * I do’nt think that’s build in so I think I need to program that myself, but since
   I am a photographer and no programmer I have no idea how to do.
 * What I’ve got for now you can see over here: [http://www.trouwshoot.nl/test-gallery/](http://www.trouwshoot.nl/test-gallery/)
 * What I want to accomplish is this: [http://www.trouwshoot.nl/foto-gallerij/](http://www.trouwshoot.nl/foto-gallerij/)
   
   This gallery get pictures from Picasa and gives me some problems with the providers
   firewall, so that’s why I need to have the pictures locally.
 * Hope that anybody can help me out since the original programmer of the Attachments
   plugin doesn’t respond at all.
 * Stefan

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Jon Christopher](https://wordpress.org/support/users/jchristopher/)
 * (@jchristopher)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-attachments-cleaner-code-indexing/#post-1688005)
 * Truth be told you’re already creating the index you’d like to use in the `for`
   loop. Instead of dumping out `$attachments[$i]['id']` dump out `$i+1` since the
   loop is zero based. Does that answer your question?
 *  Thread Starter [stefsegers](https://wordpress.org/support/users/stefsegers/)
 * (@stefsegers)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-attachments-cleaner-code-indexing/#post-1688009)
 * Hi Jonathan,
 * Thanks for the quick reply! Twitter rocks 😉
 * When I edit the code like this:
 *     ```
       <a href="javascript:void(0)"><? $i+1 ?><img src="<?=$attachments[$i]['location']?>" alt="<?=$attachments[$i]['title']?>" title="<?=$attachments[$i]['caption']?>" /></a>
       ```
   
 * I don’t get any numbers back. Maybe I am doing something wrong here?
 * What about paging? Is it possible to use pagina after 10 or 20 pictures/attachments?
 * Stefan
 *  [Jon Christopher](https://wordpress.org/support/users/jchristopher/)
 * (@jchristopher)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-attachments-cleaner-code-indexing/#post-1688012)
 * Hi Stefan,
 * There’s actually a bug, try this:
 * `<a href="javascript:void(0)"><?php echo $i+1; ?><img src="<?=$attachments[$i]['
   location']?>" alt="<?=$attachments[$i]['title']?>" title="<?=$attachments[$i]['
   caption']?>" /></a>`
 * It wasn’t set to actually echo, so that should get the value to output. Sure 
   you could technically page it, but it’d be a bit more work on your end to set
   that up.
 *  Thread Starter [stefsegers](https://wordpress.org/support/users/stefsegers/)
 * (@stefsegers)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-attachments-cleaner-code-indexing/#post-1688017)
 * Hi Jonathan,
 * You are a quick replier, thanks….
    I tried the = instead of echo… now it works.
 * Over here you can see my working page with images from Picasa. After image 20
   you see the >>> that brings you to a second page.
 * I really need the paging since I have more the 100 pictures.
 * Any hints on doping the paging?
 * What I also see is that the code that comes out has line-breaks, it’s not really
   beautifull, but t works. Any tips on cleaning the line-breaks?
 * [http://www.trouwshoot.nl/test-gallery/](http://www.trouwshoot.nl/test-gallery/)
   here’s you’ll see the breaks.
 *  Thread Starter [stefsegers](https://wordpress.org/support/users/stefsegers/)
 * (@stefsegers)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-attachments-cleaner-code-indexing/#post-1688357)
 * Hi Jonathan,
 * Did you find anything yet about the paging?
 * Stefan
 *  [Jon Christopher](https://wordpress.org/support/users/jchristopher/)
 * (@jchristopher)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-attachments-cleaner-code-indexing/#post-1688358)
 * Hi Stefan, paging isn’t built into Attachments so you’ll need to build your own
   version of paging into it. I’d suggest Googling to see what you can see — good
   luck!
 *  Thread Starter [stefsegers](https://wordpress.org/support/users/stefsegers/)
 * (@stefsegers)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-attachments-cleaner-code-indexing/#post-1688373)
 * Hi Jonathan,
 * I am looking into the code. For me it’s difficult since I am a photographer and
   no programer 🙁
 * I know a lottle basic php
 *     ```
       <?php
           $attachments = attachments_get_attachments();
           $total_attachments = count($attachments);
         ?>
         <?php if( $total_attachments > 0 ) : ?>
             <?php for ($i=0; $i < $total_attachments; $i++) : ?>
   
             <a href="javascript:void(0)"><?php echo $i+1; ?><img src="<?=$attachments[$i]['location']?>" alt="<?=$attachments[$i]['title']?>" title="<?=$attachments[$i]['caption']?>" /></a>
   
             <?php endfor ?>
       ```
   
 * This is the code to display my pictures form Attachments plugin. I see an if 
   and the $i. is there some way to make paging easy within this code or do I need
   to edit your code?
 * The code has got to be something like: if max of 10 images has reached then add
   >>> + link. If you click the new link and you get another 10 images form Attachments
   adn get a new link <<< + link that will get you 1 page back.
 * I know what the functions are but have really no idea how to code it.
 * I also tried to embed an paging-comments plugin around the pictures, but also
   didn’t work 🙁
 * a little help will do a lot for me 😀
 *  [Jon Christopher](https://wordpress.org/support/users/jchristopher/)
 * (@jchristopher)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-attachments-cleaner-code-indexing/#post-1688374)
 * Hi Stefan, I would suggest reaching out to a developer to help you out with the
   implementation. With this conversation moved beyond a question related to Attachments
   specifically I would ask that your request for assistance be moved to a better
   forum. Please feel free to [contact me](http://mondaybynoon.com/contact) any 
   time!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘[Plugin: Attachments] cleaner code indexing’ is closed to new replies.

## Tags

 * [clean](https://wordpress.org/support/topic-tag/clean/)
 * [code](https://wordpress.org/support/topic-tag/code/)
 * [gallery](https://wordpress.org/support/topic-tag/gallery/)
 * [html](https://wordpress.org/support/topic-tag/html/)
 * [index](https://wordpress.org/support/topic-tag/index/)
 * [numbering](https://wordpress.org/support/topic-tag/numbering/)
 * [output](https://wordpress.org/support/topic-tag/output/)

 * 8 replies
 * 2 participants
 * Last reply from: [Jon Christopher](https://wordpress.org/support/users/jchristopher/)
 * Last activity: [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-attachments-cleaner-code-indexing/#post-1688374)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
