We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26401
    • 247 Posts
    I’m using multiple galleries, each is inside a parent document and using the managermanager integration that metaller provided.

    What I would like to do is create a snippet that gets the first image of every gallery and the TVs inside.
    I’m okay with going through each item and getting the data, except for the image that would link it to the details with the actual gallery.
    How can I get the first image from a document’s gallery, rather than having to create, re-size a and upload a separate picture for the ’cover’.

    Thanks
      • 36416
      • 589 Posts
      Quote from: scorche at Dec 11, 2009, 12:16 AM

      What I would like to do is create a snippet that gets the first image of every gallery

      Someone already created that one - it is called MaxiGallery... smiley
      Just put it into "childgalleries" display mode. More info here:
      http://wiki.modxcms.com/index.php/MaxiGallery#Creating_your_first_gallery
        • 26401
        • 247 Posts
        Thanks, I’ve read through the documentation, and missed that (there’s quite a bit there smiley)
        However, this is not what I was looking for. I want to display additional data that’s stored in the page’s TVs and incorporating them into the gallery output doesn’t seem like the right way to go.
        I really just need an image from the gallery.
        Alternatively/Additionally It would be nice if I could set/choose the main picture to represent the gallery either through another tv (using the id), which would be fairly simple, or by adding a radio button or checkbox next to the manager template.
          • 7455
          • 2,204 Posts
          you can use maxigallery insite a ditto template like this:

          [[MaxiGallery? &gal_query_ids=`[+id+]` &limit=`1`]]

          hope this helps

          Dimmy
            follow me on twitter: @dimmy01
            • 26401
            • 247 Posts
            I’m a bit confused about this, any chance I could get you to expand on that?
              • 7455
              • 2,204 Posts
              ok if you create a ditto call like this:

              [!Ditto? &parents=`[*id*]` &tpl=`my_ditto_tpl`!]

              this is you chunk called: my_ditto_tpl
              <div class="whatever">
                 <div class="image">[[MaxiGallery?  &gal_query_ids=`[+id+]` &limit=`1`]]</div>
                 <div class="info">[+yourtvname+]</div>
              </div>
              


              notice that we use [+ here instead of [* because its used that way in ditto (and other snippets like eform, maxigallery ,etc)

              this wil get first image (depending on how you sort the images) including the default layout,
              you can create any template for the image in maxigallery, look here for more info and parameters for that:
              http://wiki.modxcms.com/index.php/MaxiGallery

                follow me on twitter: @dimmy01
                • 4172
                • 5,888 Posts
                perhaps thisone may be also usefull for your task:

                <?php
                
                /* parameters:
                 * &tpl - chunk for formatting the output
                 * &coverField - maxigallery-customField, if isset only pics with 'on' are displayed
                 * &documents - if isset, only pictures of these galleries are displayed
                 * &parents - if isset, only pictures from childgalleries of parents are displayed
                 * &depth - depth from parents
                 * &galLimit - limits pictures for each gallery
                 * &random - gets a random images for each gallery 
                 *
                 * call-example:
                 * [!maxiviewer? &tpl=`myViewerTpl`&coverField=`cover`&documents=`45,46,47`!]
                 * [!maxiviewer? &tpl=`myViewerTpl`&parents=`[*id*]`&galLimit=`1`&random=`1`!]
                 *
                 * chunk-examples:
                 * <a href="[~[+gal_id+]~]">
                 * <img src="[+path_to_gal+]thumb_[+filename+]"/>
                 * </a>
                 *
                 * <img alt="[+pagetitle+]" src="[+path_to_gal+][+filename+]" width="[+picture_width_normal+]" height="[+picture_height_normal+]"/>
                 *
                 */
                
                
                $output = '';
                if ( isset ($tpl))
                {
                    $depth = isset ($depth)?$depth:'1';
                    $coverwhere = isset ($coverField)?'mg.'.$coverField.' = "on"':'1';
                	
                
                    if ( isset ($parents))
                    {
                        $parents = explode(',', $parents);
                        $ids = array ();
                        foreach ($parents as $parent)
                        {
                            $ids = $modx->getChildIds($parent, $depth, $ids);
                        }
                        if (count($ids) > 0)
                        {
                            $documents = implode(',', $ids);
                        }
                
                    }
                
                $query = '
                select sc.pagetitle, mg.* from '.$modx->getFullTablename('site_content').' sc
                join '.$modx->getFullTablename('maxigallery').' mg on mg.gal_id = sc.id
                where '.$coverwhere;
                $galorder='menuindex';
                $picorder=isset ($random)?' rand()':' mg.pos';
                $limit= isset($galLimit)? ' LIMIT '.$galLimit:'';
                    if ( isset ($documents))
                    {
                        $rs = $modx->db->select('id as docid,pagetitle', $modx->getFullTablename('site_content'), 'id IN ('.$documents.')',$galorder);
                        $docs = $modx->db->makeArray($rs);
                        if (count($docs) > 0)
                        {
                            foreach ($docs as $doc)
                            {
                                $rs = $modx->db->query($query.' AND sc.id = '.$doc['docid'].' order by '.$picorder.$limit);
                                $docpics = $modx->db->makeArray($rs);
                				if (count($docpics)>0){
                					foreach ($docpics as $docpic){
                				        $pics[] = $docpic;
                					}
                				}
                            }
                        }
                
                    }
                    elseif (!isset($parents))
                    {
                        $rs = $modx->db->query($query.' order by sc.'.$galorder);
                        $pics = $modx->db->makeArray($rs);
                    }
                
                
                
                
                    if (count($pics) > 0)
                    {
                        foreach ($pics as $pic)
                        {
                            $pic['path_to_gal'] = 'assets/galleries/'.$pic['gal_id'].'/';
                            if (file_exists($modx->config['base_path'].$pic['path_to_gal'].$pic['filename']))
                            {
                                $imagesize = getimagesize($modx->config['base_path'].$pic['path_to_gal'].$pic['filename']);
                                $pic['picture_height_normal'] = $imagesize[1];
                                $pic['picture_width_normal'] = $imagesize[0];
                		$pic['active'] = $pic['gal_id'] == $modx->documentObject['id']?'active':'';
                            }
                            $output .= $modx->parseChunk($tpl, $pic, '[+', '+]');
                        }
                    }
                }
                
                return $output;
                
                ?>
                
                
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 7923
                  • 4,213 Posts
                  For the childgalleries display mode, there are placeholders to show TV content from the childgalleries. Just modify default childgallery templates and add the placeholders you need.

                  Or list the documents with Ditto, like Dimmy said.


                    "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                    • 26401
                    • 247 Posts
                    Thank you all, I tried the ditto first which worked, but then I needed to create another template/chunk to modify the output of [[MaxiGallery? &gal_query_ids=`[+id+]` &limit=`1`]]
                    so I just edited the childgalleryTpl to include the TVs. I didn’t realize that you could include them in the template.

                    MaxiGallery is a well documented and comprehensive extension, but with so much documentation, it’s sometimes hard to know what you’re looking for. grin