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

    I am trying to add a sortby dropdown option for my articles.

    The option to select the order of display is in the advanced tab section but i'd like to provide that option in the front end.

    Allowing users select what order they'd like to see. (Newest/Oldest).

    I tried this -
    <li><a href="[[~[[*id]]? &sortby=`ASC`]]">Newest</a></li>
    <li><a href="[[~[[*id]]? &sortby=`DESC`]]">Oldest</a></li>

    That didnt work.

    Any suggestions/solutions will be welcomed
      • 3749
      • 24,544 Posts
      I assume that you're using getResources or pdoResources for the search. The trouble is that they don't know what's in the URL. You need a custom snippet to get the query parameter from the URL:

      In the getResources tag:

      &sortby=[[!GetSortBy]]


      Then a custom snippet:

      /*GetSortBy snippet */
      return $_GET['sortby'];
      


      Also, your tags above are incorrect (you can tell by looking at the URL, which should have ? &sortby=`ASC` at the end). The parameter goes inside the link tag with no question mark:

      <li><a href="[[~[[*id]] &sortby=`ASC`]]">Newest</a></li>


      I always have to look at my own book to get this right. wink

      You could also use placeholders and a little more code in the snippet so the user would see something like:

      Sorted By Newest -- Sort by Oldest

      or

      Sorted by Oldest -- Sort by Newest
        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