• Resolved pappo87

    (@pappo87)


    Hello,
    I’m trying to find a way to add a post order switch directly on the page. If I could find a way to let the user decide to display posts by name or date order it would be great.
    The only idea I got is to create two different pages, with two different loops and two different “order=” options. Maybe we could do it with some string replace in php or with some data passed by some html checkboxes.
    Or maybe it could be integrated along with the existing pagination option.
    Thank you in advance.

    https://www.ads-software.com/plugins/custom-content-shortcode/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    Hello,

    The nicest way to do it would be via AJAX with no page reload, but that’s beyond the scope of this plugin.

    One option is to use a query variable to pass the selected order. The selector can be links to the current page with the [loop], with the order choice.

    <a href="?sort=title">Order by name</a>
    <a href="?sort=date">Order by date</a>

    Then for the loop:

    [pass global=query]
      [loop type=post orderby='{SORT}' count=5]
        [field title] - [field date]
        ...
      [/loop]
    [/pass]

    This actually uses an undocumented parameter for [pass] – I’ll add this in the reference pages in the next update.

    You can pass several parameters if you need.

    <a href="?sort=date&order=ASC">Order by date from old to new</a>
    ...
    [pass global=query]
      [loop type=post orderby='{SORT}' order='{ORDER}']
        ...
      [/loop]
    [/pass]

    I would put the {TAGS} inside quotes, in case it might be empty.

    Thread Starter pappo87

    (@pappo87)

    Hello,
    I could not get it working until I noticed there was an update. I updated the plugin and now it’s working like a charm! Thank you for the fast reply and congrats for this awesome plugin.

    Thread Starter pappo87

    (@pappo87)

    It is correct to do this:
    [if pass='{SORT}’]
    [loop type=post orderby='{SORT}’]
    [else]
    [loop]
    [/if]
    because if I don’t give parameters in the url, no posts are displayed.
    TYA

    Plugin Author Eliot Akira

    (@miyarakira)

    OK, I changed how this works in the newest update. When using global=query, you can specify the fields parameter:

    [pass global=query fields=sort]
      [loop type=post orderby='{SORT}']
        ...
      [/loop]
    [/pass]

    This way, if the query variable sort doesn’t exist, the [pass] shortcode will know to remove {SORT} and leave an empty value – in which case the loop will default to sorting from most recent date.

    Thread Starter pappo87

    (@pappo87)

    Now it’s working as I wished. Thank you for the quick updates ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘order switch on page’ is closed to new replies.