We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 356
    • 31 Posts
    Hello,

    may I please ask your for a little help?

    I’m working on site devoted to old games (actually, retro ones).

    There’ll be many sections (one section per game), and each section will have some subsections (such as ’screenshots’, ’reviews’, ’files’ etc. - I’m plan to have similar pages about each game), so the hierarchy will be like this:

    - game 1
    -- screens
    --- gallery 1
    --- gallery 2
    -- reviews
    --- review 1
    --- review 1
    -- files
    --- patches
    --- promo media
    - game 2
    ...

    Now I need to traverse the tree and get all elements specific type (say, all screenshot galleries) - this is to create list named, say, "latest screenshots".

    I understand I can get ALL children docs of all games, and then sort it ’by hands’, but I believe there should be another, more MODx-style, way to accomplish that.

    Any ideas? Please!!!
      • 3749
      • 24,544 Posts
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 22427
        • 793 Posts
        You could use the [tt]Ditto[/tt] snippet in Evo or the [tt]getResources[/tt] snippet in Revo with their flexible filtering options.
        May be a tricky way of using the menuindex could be helpful.
        Example: If you assign to all your galleries (and only to them) a menuindex greater than 500, you easily can filter out all the other resources.
          • 356
          • 31 Posts
          Quote from: ottogal at May 25, 2011, 01:24 AM

          You could use the [tt]Ditto[/tt] snippet in Evo or the [tt]getResources[/tt] snippet in Revo with their flexible filtering options.
          May be a tricky way of using the menuindex could be helpful.
          Example: If you assign to all your galleries (and only to them) a menuindex greater than 500, you easily can filter out all the other resources.

          If I just filter out pages based on it’s template name, will there be many extra DB lookups?
            • 356
            • 31 Posts
            Quote from: BobRay at May 25, 2011, 01:20 AM

            This might do what you want: http://rtfm.modx.com/display/ADDON/tagLister.getResourcesTag

            Looks like it returns all children docs that are tagged with specified tag?

            While it is solution, I also care for minimize DB queries, what you think, isn’t tags looking up will add a lot of DB requests?
              • 22427
              • 793 Posts
              If I just filter out pages based on it’s template name, will there be many extra DB lookups?
              I don’t have any knowledge about this, sorry.
                • 18373 ☆ A M B ☆
                • 3,141 Posts
                All queries in Revo are cached, and I think you can minimize them by referencing the object id instead of the name.

                I would probably consider developing (or hiring) a developer that can create a third party component to handle this instead of trying to hack together a solution with getResources filtered on templates, tags or stuff like that... but that’s just me from my developers’ point of view tongue



                I’m surprised nobody mentioned UltimateParent though tongue You can probably use that with the &topLevel parameter to find what you’re looking for.
                  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.
                  • 3749
                  • 24,544 Posts
                  I agree with Mark H.

                  It sounds like you are using the resource’s template as the search criterion. If the ID of the screenshot template is 12, something like this (untested) would get and display links to the ten most recent screenshots in a single query:

                  [[!ShowScreenShots]]


                  <?php
                  /* ShowScreenShots */
                  $c->where(array(
                      'published'=>'1',
                      'deleted'=>'0'.
                      'template'=>'12',
                  ));
                  $c->sortby('createdon', 'ASC');
                  $c->limit(10);
                  $docs = $modx﷓>getCollection('modResource', $c);
                  foreach ($docs as $doc) {
                      $output .= '<p><a href="' . $doc->get('pagetitle'). '">'  .  '[[~' . $doc->get('id')  .']]</a></p>';
                  }
                  return $output;


                  To make it more generic, you could send the template ID in the tag as a property:

                  [[!Show? &usesTemplate=`12`]]


                  and replace

                      'template'=>'12',


                  with

                      'template'=>$scriptProperties['usesTemplate'],



                  To make it truly the "MODX way," you’d put the HTML in a chunk called ShowChunk with placeholders

                  <p><a href="[[+show.pagetitle]]"> [[~[[+show.id]]]]</a></p>


                  Then in the loop in your snippet:

                  $fields = array(
                      'show.pagetitle'=>$doc->get('pagetitle'),
                      'show.id'=>$doc->get('id');
                  }
                  
                  $output .= $modx->getChunk('ShowChunk, $fields); 
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 356
                    • 31 Posts
                    Quote from: BobRay at May 26, 2011, 01:26 AM

                    To make it truly the "MODX way,"

                    Oh, thank you! Honestly, this kind of answer should be marked as ’master class’, at least as for me. Not only answers my single problem, but also pointing to the right direction. Thank you again!

                    P.S. I used to use Evo, but this time want to use Revo (2.1, the latest one, just to be familiar with; beside endless ’wait please’ AJAX it looks great as far smiley ), so it’s a bit fuzzy for me how effective cache can be in such a case - so I’ll test it soon and write back here with results.
                      • 3749
                      • 24,544 Posts
                      Don’t thank me until it works. wink

                      For others following this thread, none of the code above will work in Evolution, though the principles are the same.
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting