We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7527
    • 437 Posts
    Hi, I am trying to create what I think should be a rather simple process. I want a link that lists specific containers as a text-link, with a children count next to it, (i.e, Insects (2) ). When clicked the link goes to a landing page that lists the articles within the chosen container (pagetitle, link, etc)

    I can manage the template output myself but am having difficulty picking the right snippet and getting it started. It seems like a similar process to Archivist

    Any pointers would be great
    DS
      www.PawsForWildlife.co.uk
      www.Borntobrick.co.uk
      • 3749
      • 24,544 Posts
      I can't think of a way to do that without a custom snippet, though maybe some else can. IIRC, Archivist is designed to organize the output by date, not by parents and children. It might work if you use large enough date range, but I don't think it's going to give you a link to a page that will show the children.

      Wayfinder plus a simple snippet in the Tpl chunk to show the child count would be easy enough, but that won't give you a link to the page showing the children without some tricky custom work.

      The easiest solution would be to use Wayfinder to create a big menu with all the parents and their children (including the child count if you want to). You could hide the children until the parent is clicked on with a little JavaScript or use CSS to have the children drop down when you hover over the parent. The menu for Bob's Guides displays the children with JavaScript (see my sig.).

        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
        • 7527
        • 437 Posts
        Good morning,

        Thanks BobRay. I did try the wayfinder snippet. It output the container name, and when hovered it listed the children below. The only issue is that some of the children have long pagetitles that then clutter up the sidebar. I can get a container output with Wayfinder, but no count and no link to a landing page. The only option I can think of is to give a short pagetitle in the sidebar, but make the actual page display a longer longtitle?
        DS
          www.PawsForWildlife.co.uk
          www.Borntobrick.co.uk
          • 3749
          • 24,544 Posts
          You can display the pagetitle, longtitle, summary (introtext), description, menutitle, or alias in either location. I would think one of those could be short enough.

          This should give you the count:

          ([[!ChildCount? &parent=`[[+id]]` ]])


          /* ChildCount snippet */
          $docId = $modx->getOption('parent', $scriptProperties, '');
          $count = $modx->getCount('modResource', array('parent' => $docId));
          return $count? $count : '0';



          If you want to have a separate landing page. You might be able to do something like this (making the child count a link -- untested):

          /* ChildCount snippet */
          $landingPageId = 12; // this will always be the same page
          $docId = $modx->getOption('parent', $scriptProperties, '');
          $count = $modx->getCount('modResource', 'parent' => $docId));
          $count = $count? $count : '0';
          
          if (!empty($count))  {
             $url = $modx->makeUrl($landingPageId, '', array('parent_id' => $docId));
             $output =  '<a href="' . $url . '" >' . $count . '</a'>;
          } else {
             $output = '0';
          }
          return $output;
          


          Then on your landing page, do this:
          [[!GetParent]]
          [[!Wayfinder? &startId=`[[+parentId]]` ... ]]
          


          /* GetParent snippet */
          $modx->setPlaceholder('parentId', $_GET['parent_id']);
          return '';






          [ed. note: BobRay last edited this post 10 years, 7 months ago.]
            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
            • 7527
            • 437 Posts
            Hi BobRay I tried the Childcount snippet and got the following error?

            Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in /homepages/10/d568633693/htdocs/core/cache/includes/elements/modsnippet/55.include.cache.php on line 5


              www.PawsForWildlife.co.uk
              www.Borntobrick.co.uk
              • 3749
              • 24,544 Posts
              Sorry, my bad. Here's a (hopefully) corrected version of the ChildCount snippet:

              /* ChildCount snippet */
              $landingPageId = 12; // this will always be the same page
              $docId = $modx->getOption('parent', $scriptProperties, '');
              $count = $modx->getCount('modResource', array('parent' => $docId));
              $count = $count ? $count : '0';
               
              if (!empty($count)) {
                  $url = $modx->makeUrl($landingPageId, '', array('parent_id' => $docId));
                  $output = '<a href="' . $url . '" >' . $count . '</a>';
              } else {
                  $output = '0';
              }
              return $output;
              
              [ed. note: BobRay last edited this post 10 years, 7 months ago.]
                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
                • 7527
                • 437 Posts
                Hi BobRay thanks onc again, unfortunately another error:

                Parse error: syntax error, unexpected ';' in /homepages/10/d568633693/htdocs/core/cache/includes/elements/modsnippet/55.include.cache.php on line 10


                  www.PawsForWildlife.co.uk
                  www.Borntobrick.co.uk
                  • 4172
                  • 5,888 Posts
                  this line should be:

                  $output = '<a href="' . $url . '" >' . $count . '</a>';
                  
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 7527
                    • 437 Posts
                    Ok well I could not get it all to come together. But I have chosen to use the following in my sidebar instead:

                    [[!GetParent]] [[!Wayfinder? &startId=`7` &rowTpl=`7in1menuRow` &innerTpl=`7in1menuInner` &innerRowTpl=`7in1ImenunnerRow` &hereClass=`current_page_item` &ignoreHidden=`1`]]								</div>


                    It displays the parent title, with the children listed underneath, nearly perfect. I was hoping to show just the parent but when clicked it expands the children underneath in a bullet point style. my templates are:

                    7in1menuInner
                    <ul>[[+wf.wrapper]]</ul>


                    7in1menuInnerRow
                    <li [[+wf.classes]]><a href="[[+wf.link]]" title="[[+wf.title]]" [[+wf.attributes]]><span>[[+wf.linktext]]</span></a>[[+wf.wrapper]]</li>


                    7in1menuOuter
                    <ul class="sf-menu">[[+wf.wrapper]]</ul>


                    7in1menuRow
                    <li [[+wf.classes]]><a href="[[+wf.link]]" title="[[+wf.title]]" [[+wf.attributes]]><span>[[+wf.linktext]]</span></a>[[+wf.wrapper]]</li>


                    Here is an example page
                    http://www.pawsforwildlife.co.uk/blog/


                    As you can see it lists parent and children, but want it to work more like the navigation bar (dropdown menu style).
                      www.PawsForWildlife.co.uk
                      www.Borntobrick.co.uk
                      • 3749
                      • 24,544 Posts
                      Quote from: Bruno17 at Feb 28, 2016, 06:07 AM
                      this line should be:

                      $output = '<a href="' . $url . '">' . $count . '</a>';
                      

                      Thanks Bruno -- corrected above. I didn't follow my own rule about not posting code without looking at it in PhpStorm first. 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