We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33982 ☆ A M B ☆
    • 476 Posts
    The site referenced below is running on MODX 2.2.6-pl on a standard LAMP environment.

    So here's what I'm attempting to do: I've got individual portfolio pages on my site. These portfolio pages are all child resources of a Container named "Portfolio". So in the MODX tree I have a basic setup like this:

    -- Portfolio
    --- ABC Widgets
    --- XYZ Widgets
    --- ACME products inc.
    --- Cool Company Project
    etc.

    Each one of these child Resources of "Portfolio" has a T.V. named "Work Category". The "Work Category" is a T.V. with radio options pulling the names of child Resources from a container that I have in the tree named "Work Category". The "Work Category" is a container which child resources like "Web Design", "Print", "Packaging", "CMS", etc. When I setup a new Portfolio page to put in the "Portfolio" container, I choose from the radio options which category this Portfolio item is categorized.

    So here's my challenge. When a visitor views anyone of the Portfolio pages above, I will have a link the user can click named "Next Project" so they can view the next portfolio item in the tree that has the same T.V. Category chosen for the "Work Category". My goal is that every time they click "Next Project", they basically are traversing the MODX tree to find the next resource tagged with the same T.V. They'll basically be cycling through the tree. Hope that makes sense.

    Thanks!
      Precision Web Development ... SmashStack.com
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      I think you'd have to do something custom with a getCollection query... don't know if there's anything pre-packaged that will do this for you.
        • 3109 ☆ A M B ☆
        • 894 Posts
        So let me see if I understand you correctly, you want to go from ACB Widgets Work Category to XYZ Widgets Work Category items?

        I can't quite understand if you want to traverse from ABC Widgets to XYZ Widgets or from ABC Widgets Work Category Items to XYZ Widgets Work Category items.

        I think you could probably make a navigation using getResources and filter which resources by the TV value of the category, again I'm not clear on what you want to achieve.
          Benjamin Marte
          Interactive Media Developer
          Follow Me on Twitter | Visit my site | Learn MODX
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          That's just tagging; this would be no different than having links to items with the same tag. I think there are some extras that deal with this.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 33982 ☆ A M B ☆
            • 476 Posts
            Quote from: benmarte at Jan 31, 2013, 07:15 PM
            So let me see if I understand you correctly, you want to go from ACB Widgets Work Category to XYZ Widgets Work Category items?

            I can't quite understand if you want to traverse from ABC Widgets to XYZ Widgets or from ABC Widgets Work Category Items to XYZ Widgets Work Category items.

            I think you could probably make a navigation using getResources and filter which resources by the TV value of the category, again I'm not clear on what you want to achieve.

            Hey benmarte, thanks for asking me to clarify that...sorry if I didn't communicate that point well. I want to traverse the tree to go to the next Resource that has the same T.V. category tagged as the current Resource being viewed. So if a visitor is on a page that is tagged in MODX as "CMS", when they click the next page link, it will take them to the next Resource in the MODX tree that is tagged with "CMS" for that same T.V. You can see a live example on a site I recently viewed:

            http://viget.com/work/hellowallet

            If you notice on the left and right side of the page, there are arrows leading the site visitor to the either the next page that is in the db. Not sure how exactly they're deciding what is the next page (publication date or some other variable), but I'm trying to recreate that same UI functionality, but I just need to figure out how to traverse the MODX tree to find the previous and next Resource that is tagged with the same category.

            Hope that helps.
              Precision Web Development ... SmashStack.com
              • 3749
              • 24,544 Posts
              I think you want something like this snippet (untested):

              <?php
              $tvId =12; /* ID of the WorkCategory TV */
              
              /* get the category for this page */
              $currentCategory = $modx->resource->getTVValue($tvId);
              
              /* you probably want to make this a query with sortby */
              $tvrs = $modx->getCollection('modTemplateVarResource', array('tmplvarid' => $tvId, 'value' => $currentCategory));
              
              /* Now you have an array of modTemplateVarResource objects for Resources with the same category
              (will include the current one). */
              
              /* make a new array of Resource Ids to get consecutive indexes (0,1,2,... */
              
              $linkList = array();
              $output = "";
              
              foreach($tvrs as $tvr) {
                  $linkList[] = $tvr->get('contentid')
              }
              
                  /* grab the index of the current resource */
              $current = array_search($modx->resource->get('id'), $linkList);
              $maxIndex = count($linkList) - 1;
              
              /* Previous link for all but first doc */
              if ($current != 0) {
                  $url = $modx->makeUrl($linkList[$current - 1], "", "", "full");
                  $output .= '<a href="' . $url . '">Previous -</a>';
              } else {
                  $output .= 'Previous -'; /* non link */
              }
              
              /* Next link for all but the last doc */
              if ($current < $maxIndex) {
              $url = $modx->makeUrl($linkList[$current + 1], "", "", "full");
              $output .= '<a href="' . $url . '">- Next</a>';
              } else {
                  $output .= '- Next'; /* non link */
              }
              
              return $output;
              




                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
                • 33982 ☆ A M B ☆
                • 476 Posts
                Hey BobRay,

                Thanks so much...this is really good stuff. I'm gonna play around with this code right now. Thanks!
                  Precision Web Development ... SmashStack.com
                  • 3749
                  • 24,544 Posts
                  Don't thank me until it works. wink

                    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