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

    Im trying to find an easy way to output a list of all the resources (parents & children) on my website but as a single UL, so no nested UL for children, just all pages in one single UL, any ideas??

    Brett
      • 22427
      • 793 Posts
      Consider to use getResources instead of Wayfinder. WF is meant to reflect the hierarchy of the resources tree.

      Edit:
      With Wayfinder you could try the parameter &parentRowTpl.
      [ed. note: ottogal last edited this post 11 years, 11 months ago.]
        • 3749
        • 24,544 Posts
        I could be wrong, but I don't think Wayfinder will do this. Even if it could, this would probably be quicker and easier:


        [[ShowAllResources]]



        <?php
        /* ShowAllResources Snippet */
        
        $query = $modx->newQuery("modResource");
        $query->select(array(
            'id'        => 'id',
            'pagetitle'     => 'pagetitle',
            'published' => 'published',
            'deleted' => 'deleted',
        ));
        
        $query->where(array('published' => '1', 'deleted' => '0'));
        
        /* uncomment the next line if you want them sorted */
        // $query->sortby('pagetitle', 'ASC');
        
        $results = array();
        
        if ($query->prepare() && $query->stmt->execute()) {
            $results = $query->stmt->fetchAll(PDO::FETCH_ASSOC);
        }
        $output = "\n" . '<ul class="sa_resources_ul">';
        foreach($results as $doc) {
            $output .= "\n   " . '<li class="sa_resources_li"><a href="[[~' . $doc['id'] . '"]]>' . $doc['pagetitle']. '</a></li>';
        }
        $output .= "\n</ul>";
        
        return $output;
        
        


        I'm assuming that you want them to be links.

        It's very easy to sort them alphabetically by pagetitle, by createdon, by editedon, by menuindex, or by published date if you like, and shouldn't make it noticeably slower. You could also wrap it with getPage if you have a lot of resources and want to let the user page through them.

        FYI, there is also the SiteAtoZ snippet, but the code above will be a lot faster.







        [ed. note: BobRay last edited this post 11 years, 11 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
          • 22427
          • 793 Posts
          Another idea (using Wayfinder): Modify the default outerTpl by omitting the wrapping ul tag:
          &outerTpl chunk "outer":
          [[+wf.wrapper]]

          Then wrap the whole Wayfinder call in a ul tag:
          <ul>
          [[Wayfinder? ..... &outerTpl=`outer`]]
          </ul>

          (Not tested.)
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            I would use getResources (actually I use pdoTools so I would use pdoResources) for this. But BobRay's code would be faster.
              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
              • 22969
              • 158 Posts
              Thanks everyone,

              Going for BobRays idea first, its working although not actually filling in the text for the link itself? So nothing showing on the page itself.

              <li class="sa_resources_li"><a href="contact-us></li>


              Also is showing all my "Articles" based news items which is logical but on reflection can I omit any section/pages? Just the news really.

              Thank you for your help.

              Brett
                • 23018
                • 353 Posts
                Hi Brett,

                the script basically does what you want it to do, but Bob's code is missing the pagetitle. I guess he was in a hurry.

                Try this:
                -------

                1. Create a new chunk. Call it resourcelist_tpl

                <li>
                <a href="[[~[[+id]]]]" 
                style="color:[[+published:is=`1`:then=`black`:else=`gray`]]; font-style:[[+hidemenu:is=`1`:then=`italic`:else=`normal`]]"
                >
                [[+pagetitle]] ([[+id]])
                </a>
                </li>
                


                2. Use this slightly modified version of Bob's solution. Its easier for you to maintain and modify:

                P.S. If you only want to show all resources below the "news" resource, add the news id to the where parent= on line 17 below.

                <?php
                /* ShowAllResources Snippet */
                 
                $query = $modx->newQuery("modResource");
                $query->select(array(
                    'id'        => 'id',
                    'pagetitle' => 'pagetitle',
                    'published' => 'published',
                    'deleted'   => 'deleted',
                    'hidemenu'  => 'hidemenu'
                    'parent' => 'parent'
                ));
                 
                $query->where(array(
                     'deleted' => '0'
                     /* Add the id of the parent of your news section below */
                     'parent' => '1'
                    /* Uncomment the next line, if you don't want to display unpublished resources. */
                    //,'published' => '1' 
                ));
                 
                /* uncomment the next line if you want them sorted */
                // $query->sortby('pagetitle', 'ASC');
                 
                $results = array();
                 
                if ($query->prepare() && $query->stmt->execute()) {
                    $results = $query->stmt->fetchAll(PDO::FETCH_ASSOC);
                }
                $output = "\n" . '<ul class="sa_resources_ul">';
                foreach($results as $resourceArray) {
                    $msg .= print_r($resourceArray,true)."<br/>";
                    $output .= $modx->getChunk('ShowAllResources_tpl',$resourceArray);
                }
                $output .= "\n</ul>";
                 
                return $output;
                


                Cheers,

                Patrick [ed. note: pepebe last edited this post 11 years, 11 months ago.]
                  Homepage: pepebe.de | MODX snippets (and other stuff) at github: https://gist.github.com/pepebe
                  • 3749
                  • 24,544 Posts
                  Quote from: pepebe at Oct 13, 2014, 07:14 AM
                  Hi Brett,

                  the script basically does what you want it to do, but Bob's code is missing the pagetitle. I guess he was in a hurry.

                  I plead sleep deprivation. wink

                  It was also missing the closing a tag. Fixed above (hopefully).

                  I intentionally didn't use a Tpl chunk to speed it up by avoiding getting the Tpl chunk and parsing it for each resource.
                    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
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    It might also be worth trying to have the &innerTpl like this:
                    [[+wf.wrapper]]

                    With no inner <ul> </ul> tags, it should just list all of the resources in the same order they would be in if the list were nested. It all depends on how you want the items ordered.
                      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