WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Attachments] cleaner code + indexing (9 posts)

  1. stefsegers
    Member
    Posted 3 years ago #

    Hi all,

    finally found a gallery plugin that outputs exactly what I want.

    %INDEX%<img src="%THUMBNAILPATH%" alt="%IMAGETITLE%" title="%IMAGEDESCRIPTION%" />

    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/

    What I want to accomplish is this: 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

  2. Jonathan Christopher
    Member
    Posted 3 years ago #

    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?

  3. stefsegers
    Member
    Posted 3 years ago #

    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

  4. Jonathan Christopher
    Member
    Posted 3 years ago #

    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.

  5. stefsegers
    Member
    Posted 3 years ago #

    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/ here's you'll see the breaks.

  6. stefsegers
    Member
    Posted 3 years ago #

    Hi Jonathan,

    Did you find anything yet about the paging?

    Stefan

  7. Jonathan Christopher
    Member
    Posted 3 years ago #

    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!

  8. stefsegers
    Member
    Posted 3 years ago #

    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 :D

  9. Jonathan Christopher
    Member
    Posted 3 years ago #

    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 any time!

Topic Closed

This topic has been closed to new replies.

About this Topic