We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39559
    • 34 Posts
    I didnt want to start a thread on this, but I have been literally banging my head into a wall for days trying to figure this out.
    MODX Revolution 2.2.0-pl2 (traditional)
    PHP Version 5.2.17

    I have a website I am putting together for my wife (she hates Wordpress and most everything else I showed her)
    This is mainly a photography site, with very little content on it, aside from the photos.

    structure is lined out like this:

    Home page contains a small slideshow, and basic navigation around the site. at the bottom of the page is a featured posts section (recent galleries) <<this is what is haunting me at the moment
    navigation of the site goes like this:
    Locations jump page->Type of Location (school, hospital, etc)->actual destination (the name of a school, hospital, etc)
    on the ACTUAL DESTINATION page are basically thumbnails that link to 3 galleries (one for each of the users) so that each person has their own subsection of a destination

    gallery structure is laid out pretty much IDENTICAL to the navigation structure, to keep things on a 1:1 scale so it makes sense to the users. they click on ADD resource, name it, select a parent gallery for that location, then everything is automatically generated for them. all this layout is good at the moment, thanks to some awesome tips here in the forums and help from IRC folks.

    the problem is with my getResources call (the FEATURED POSTS section).
    using this page as a reference (this works by the way)
    https://forums.modx.com/thread/73571/using-galleryitem-with-getresources-produces-duplicate-images-in-modx-revolution
    i can get the images to display properly.
    there are 2 problems with this method though:
    1. this requires the user to select a TV image to be used as a 'FEATURED POSTS' thumb
    2. the GalleryItem input type contains too many options. i want this as automated as possible. user selects an image and thats it. no options for them to muck up.

    ideally i would prefer that the getResources call pull a random image from any of the child galleries located on the page that the call is referencing.

    HELP?

    i realize that a custom snippet would probably be ideal for this, but i am clueless on where to begin. i have been all over rtfm with a fine tooth comb, searching these forums for days, and bugged enough people on IRC.... [ed. note: pirateghost last edited this post 14 years, 2 months ago.]
      • 39559
      • 34 Posts
      nothing? not a soul?
        • 18373 ☆ A M B ☆
        • 3,141 Posts
        Showing your current set up would help.

        I would imagine you'd just throw the GalleryItem into your getResources chunk and have that fetch a random image using a Gallery call limited to 1 with a sort of "rand".

        Using a TV to manually select one (like you're doing now, I think?) is one option, but as with a lot in MODX not the only way,
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • 27708 MODX Staff
          • 2,502 Posts
          @pirateghost, Sorry for your troubles and please share your setup as Mark suggests. But please reach out in the forums ASAP if you're stuck and then share on Twitter with the #modx hashtag and we'll try to help. There are no noob haters here and certainly no stupid questions.

          This sounds like a completely achievable outcome so the more details you can provide including your calls and perhaps a screenshot of the setups you have too.
            Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
            • 39559
            • 34 Posts
            Thanks guys.
            right now, i have tons of chunks so i can swap things in and out to try different configurations on crap that MIGHT work...lol.

            here is my home page:
            [[$head]]
            
            <body lang="en">
            [[$top_widget]]
            [[$header]]
            <!-- MAIN -->
            <div id="main">	
              <div class="wrapper">
              [[$slider]]
            
            <!-- home-block -->
            <div class="home-block" >
              <h2 class="home-block-heading"><span>FEATURED POSTS</span></h2>
              <div class="one-third-thumbs clearfix" >
                [[$featured_content]]
              </div>
            </div>
            <!-- ENDS home-block -->
            
            [[$addthis]]
              </div>
            </div>
            <!-- ENDS MAIN -->
            
            [[$footer]]
            [[!updatehits]]
            </body>
            </html>


            featured_content:
            [[!GetResources?
              &parents=`10,16`
              &limit=`9`
              &includeContent=`1`
              &includeTVs=`1`
              &processTVs=`1`
              &tpl=`featuredPostsTpl`
              &sortby=`publishedon`
              &sortdir=`desc`
              &hideContainers=`1`
            ]]


            featuredPostsTpl:
            [[!GalleryItem? &id=`[[!getPicId? &imageTV=`[[+tv.featured_thumb]]`]]` &imageWidth=`300` &imageHeight=`187` &thumbProperties=`{"iar":"1"}`]]
            
            <ul class="prettyGalleryThumb">
            <figure>
            <figcaption>
            <h1><strong>[[+pagetitle]]</strong></h1>
            <a href="[[~[[+id]]]]" title="[[+pagetitle]]" class="opener">[[+pagetitle]]</a>
            </figcaption>
            <a href="[[~[[+id]]]]" title="[[+pagetitle]]" class="thumb"><img src="[[+galitem.image]]&zc=1&fltr[]=wmt|%A9 2012 WATERMARK|12|C|FFFFFF|/assets/fonts/calibri.ttf|40|20|0||0|" /></a>
            </figure>
            </ul>


            like i said, this setup works, but i dont like having to select a TV for a thumbnail on the front page. my wife wants to keep it extremely simple for the others that will be contributing to the content on the site. i would assume that pulling a thumbnail automagically would be the easiest method for the end user.

            thanks for taking the time to look guys.

            by the way, i totally posted this in the wrong section....i dont think it should be in modx101...lol
              • 18373 ☆ A M B ☆
              • 3,141 Posts
              Surprised that works, last time I checked snippetnames were case sensitive and getResources is in camelCase tongue

              Anyway.

              Replace the GalleryItem snippet with something like this:

              [[Gallery? &albums=`name or id of album` &limit=`1` &sort=`rand`]]
              

              where "name of id or album" is an album select tv or some other logic that finds the relevant album.
                Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                • 39559
                • 34 Posts
                LOL. yeah, in all my swapping around things, i got that one case wrong.

                the problem with using that call is that, it doesnt work, because i need &album= to be dynamic based on whatever album/sub-albums are on the resource that it links to.

                using the plain Gallery? snippet, yields no img at all. unless i point it to an id of a gallery, in which case, defeats the purpose of trying to make it dynamic. tongue
                  • 39559
                  • 34 Posts
                  any other ideas?
                    • 39559
                    • 34 Posts
                    I need to bump this, as my wife is unhappy with the lack of Featured Posts section...and I haven't had the time to learn PHP to attain this.

                    If anyone thinks they can help, it would be appreciated. Would it help to link the site on here?
                      • 39559
                      • 34 Posts
                      i think what i need is to create a modified Gallery snippet that will pull a random image from a child album rather than stopping at the parent album like it currently does.

                      enogu helped me out with something similar for the GalleryAlbums snippet and it worked perfectly, but i dont have the slightest idea how to replicate that for the Gallery snippet.

                      this looks like the modified section of GalleryAlbums that enogu helped me with:

                      foreach ($albums as $album) {
                          $albumArray = $album->toArray();
                          $c = $modx->newQuery('galItem');
                          $c->innerJoin('galAlbumItem','AlbumItems');
                      
                          $albumIds = array($album->get('id'));
                          $children = $album->getMany('Children');
                          while (!empty($children)) {
                            $child = array_shift($children);
                            $albumIds[] = $child->get('id');
                            $children = array_merge($children, $child->getMany('Children'));
                          }
                          $c->where(array(
                              'AlbumItems.album:IN' => $albumIds,
                          ));
                          $c->sortby($albumCoverSort,$albumCoverSortDir);
                          $c->limit(1);
                          $coverItem = $modx->getObject('galItem',$c);


                      any idea how to replicate something like this for the Gallery snippet?