We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35103
    • 54 Posts
    How do I set which album the GalleryItem is getting the images from?

    I'd have thought this was very simple, but I can't see any examples of this. Or do I need a different approach?

    Thanks,

    David
      • 28000 ☆ A M B ☆
      • 397 Posts
      Are you referring to Shaun's Gallery Add on?
      http://rtfm.modx.com/display/ADDON/Gallery

      You can use a snippet call like this
      [[!Gallery? &album=`My Album`]]


        Benjamin Davis: American web designer living in Munich, Germany and a MODX Ambassador. I am also co-founder of SEDA.digital, a MODX Agency.
        • 35103
        • 54 Posts
        Hi Ben Davis,

        Yes that is the plugin i'm using.

        Could you give me an example of how to set which album the GalleryItem is called from?

        The below code does not pull in the correct image, it only ever pulls in the image from the first gallery

        [[!Gallery? &album=`2` ]]
        [[!GalleryItem? &id=`1` ]]
         
        [[!+galitem.image:notempty=`
        <div class="image">
          <a href="[[+galitem.image]]">
            <img src="[[+galitem.image]]" alt="[[+galitem.name]]" />
          </a>
          <br />Albums: [[+galitem.albums]]
          <br />Tags: [[+galitem.tags]]
        </div>
        `]]


        Thanks in advance for any advice,

        David
          • 28000 ☆ A M B ☆
          • 397 Posts
          You shouldn't need to know which album. Each image in the Gallery add-on gets its own ID, independent of album. That means that you only ever need to give it the id of the photo if you really need to do it that way. So if I have album 1 with 4 images and album 2 with 4 images, the images would have ID numbers 1 through 8. IDs 1 -4 would belong to album 1 and IDs 5 - 8 belong to album 2.

          Try finding the id of the image you are looking for and put that into
          [[!GalleryItem? &id=`1` ]]
            Benjamin Davis: American web designer living in Munich, Germany and a MODX Ambassador. I am also co-founder of SEDA.digital, a MODX Agency.
            • 35103
            • 54 Posts
            OK thanks for pointing that out!

            But if I try and use that with the GalleryItemPagination snippet I setup, the navigation doesn't tally and pressing 'next' reverts to photo with id 2.

            If I try and set &album=`2` in the GalleryItemPagination then it pulls an error.

            <div>
            [[!GalleryItem? &id=`5` ]]
            <img src="[[+galitem.image]]" alt="[[+galitem.name]]" />
            </div>
            
            
            <div>
            [[!GalleryItemPagination? ]]
            [[!If? &subject=`[[!+galitem.prev.id]]`&operator=`isnotempty` &then=`
            <a id="previmg" href="[[++site_url]]?id=[[*id]]&galItem=[[!+galitem.prev.id]]&galAlbum=1&galTag=">previous</a>`]]
             
            [[!If? &subject=`[[!+galitem.next.id]]`&operator=`isnotempty` &then=` / `]]
             
            [[!If? &subject=`[[!+galitem.next.id]]`&operator=`isnotempty` &then=`
            <a id="nextimg" href="[[++site_url]]?id=[[*id]]&galItem=[[!+galitem.next.id]]&galAlbum=1&galTag=">next</a>`]]
            
            </div>
            


            error if I try to set the album to something other than `1` in GalleryItemPagination:
            Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 24 bytes) in /home/patchdol/public_html/core/model/modx/error/moderrorhandler.class.php on line 95
            


            I am confused!
              • 28000 ☆ A M B ☆
              • 397 Posts
              The GalleryItem snippet only shows the one item, I believe.

              Check out this post:
              https://forums.modx.com/thread/74574/pagination-for-gallery-albums#dis-post-418376

                Benjamin Davis: American web designer living in Munich, Germany and a MODX Ambassador. I am also co-founder of SEDA.digital, a MODX Agency.
                • 35103
                • 54 Posts
                Hi Ben,

                Thanks for the link, I'm looking over it and hopefully take something from it to help me. However I only want to show one item at a time from a single album so galleryItem and galleryItemPagination really should be fine.

                The problem I am having is the galleryItem snippet only accepts an &id parameter for the image and the galleryItemPagination snippet only accepts an &album parameter. I see no way of telling the galleryItem to be the first in an album (without finding the id value of the image) and if I try and set the &album parameter of the galleryItemPagination to anything other than `1` it pulls an error.

                Is there a way of fetching the id of the first image in an album? or using the galleryItemTV to output a selected image id rather than a whole galleryItem?

                I have no php experience so can't really write my own snippets. I find the documentation on Gallery a little confusing at times- it jumps from very simple calls to adding in a lot of parameters requiring interaction. I'm sure the gallery I'm after is simpler than half the examples! Display a single image from an album and have prev / next buttons to advance through an album. I really just need some simple navigation added to a galleryItem!!!

                Thanks for taking a look at my problem,

                David
                  • 28000 ☆ A M B ☆
                  • 397 Posts
                  Hello David,

                  First of all, make sure that you have your gallery call with the album name.
                  [[!Gallery? &album=`My Album`]]

                  I usually have the album name be a template variable where the admin writes in the name of the album that they created.
                  [[!GalleryItem]]
                  is the placeholder for the large image in the gallery
                  This code is for your thumbnails:
                  [[!+galitem.image:notempty=`
                  <div class="image">
                    <a href="[[+galitem.image]]"><img class="[[+galitem.imgCls]]" src="[[+galitem.image]]" alt="[[+galitem.name]]" /></a>
                  </div>
                  `]]


                  To determine which image is the first image, you just go into your Gallery component. Then right click on your album to open it. Then you should get a list of images. You can just select images and slide them around to the positions that you want. Make sure to save your changes.

                  Now as far as the pagination goes...I can't answer that one because when I used this add-on, I used it with the Galleriffic plugin. This plugin takes care of the pagination through javascript and does it automatically.
                    Benjamin Davis: American web designer living in Munich, Germany and a MODX Ambassador. I am also co-founder of SEDA.digital, a MODX Agency.
                    • 35103
                    • 54 Posts
                    Maybe I should just try the Gallerific plugin?

                    I have a template variable for the album setup already, as you suggested.

                    When I check page with Chrome dev tools Inspector I think the final bit of code you posted is for the large image generated by GalleryItem. I think all the thumbnails are generated by the Gallery snippet.

                    What I'm after is so simple I can't believe I haven't found an example of the code yet.

                    Think I'm going to have to learn some php!!!
                      • 28000 ☆ A M B ☆
                      • 397 Posts
                      You could also try to use MIGX and create an image upload tool for the admin user. http://rtfm.modx.com/display/ADDON/MIGX

                      This would give you the flexibility to output your images any way you like. You can make your own chunk as a tpl using placeholders. I am currently doing this in conjunction with Galleria for the frontend interface. http://galleria.io/

                      I tried to use the Gallery Addon at first, but couldn't write the code the way I needed to. So I used MIGX and in 20 minutes I had it finished!
                        Benjamin Davis: American web designer living in Munich, Germany and a MODX Ambassador. I am also co-founder of SEDA.digital, a MODX Agency.