How can I add a sort field to the Simple Navigation macro?

I am using the Simple Navigation macro on my website within a specific area. It works well, except when I click on next or previous it goes to the next tiddler in alphabetical order, instead of created order. I’m hoping this can be rectified.

Is anyone able to help me to add a sort function please?

The docs says:

The sequence (order) of tiddlers can be simply changed using the tag pill!

So it seems the macro uses the list field of the tag tiddler to define the order. So you’ll need to open the tag-dropdown and there you can sort by drag & drop.

Eg: If you open HelloThere at tw-com you can change the order of the TOC with dnd

image

-m

Sorry, I’ve mislead you. I don’t mean in a navigation bar. I’m attempting to add “previous | next” to the bottom of tiddlers within a specific section of my website using the tag “Reading”. I’ve worked out how to use the macro and it works well, but when I click on next the result is not date related. It’s alphabetical, which doesn’t work for me.

Here’s a snippet of the original code for the Simple Navigation macro.

The first line shows the parameters as “tag”, “class” and “close”. I want to add “date”. But I know that adding date in that line isn’t enough. I also need to add code in the previous and next sections, but I don’t know where to add the code or what code to add.

I think it will be something starting with list filter, but I’m out of my depth.

I know the code in the previous section needs to take the user back to the previous post and the code in the next section needs to take the user forward to the next post. I also know that I want to use the “created” option. But that’s all I can work out on my own.

I’ve tried some things, but nothing worked, or I broke the macro. Can you help please?

Try this:

\define simple-navigation(tag:"demo",class,close:"no",sort:"title")
...
<$list filter="[tag<__tag__>sort<__sort__>before<currentTiddler>]" variable="prevTiddler">
...
<$list filter="[tag<__tag__>sort<__sort__>before<currentTiddler>] [tag<__tag__>sort<__sort__>after<currentTiddler>] +[count[]] -1">|<$list>
<$list filter="[tag<__tag__>sort<__sort__>after<currentTiddler>]" variable="nextTiddler">

Then, to sort by a specified field (e.g., “created”), pass that field name as the 4th parameter for the macro.

Note: you can optimize performance a bit by pre-calculating the list of tiddlers.

Add the following line at the start of the macro (just after the \define line):

<$set name="tids" filter="[tag<__tag__>sort<__sort__>]">

Then, in the subsequent filters, replace this part of the filter syntax:

tag<__tag__>sort<__sort__>

with:

enlist<tids>

enjoy,
-e

1 Like

For a slightly different approach, see my WizardNav plugin (my first-ever plugin!) and the discussion at WizardNav Plugin: Initial Release.

With that plugin, you add a prev/next footer for any tag that itself has the tag Wizard (or some other configurable value.)

@EricShulman I attempted to do what you instructed but this is the result.


The above goes on and on down the page.

Can you check that I’ve put the code in the right places, and made the right changes please. Here’s what I’ve done:
TW-SimpleNavCode-amended

@Scott_Sauyet I actually tried this plugin yesterday, but couldn’t work out how to get it to work for two values. I could see you had it working for Tutorial and Pathway so I believe it’s possible. My issue is that I don’t want to have to drag and drop posts into the order I want because I have over 100 tiddlers in each section. I want something that sorts by date created.

You left the old $list widgets in place!
Get rid of the lines that have <$list filter="[tag<__tag__>...

Next, you are missing an [ before enlist on this line:

<$list filter="enlist<tids>before<currentTiddler>]" variable="prevTiddler"

and there is a typo (my fault) on this line:

<$list filter="[tag<__tag__>sort<__sort__>before<currentTiddler>] [tag<__tag__>sort<__sort__>after<currentTiddler>] +[count[]] -1">|<$list>

which should end with </$list> instead of <$list>.

Let me know how it goes.

-e

@EricShulman Thank you. Those last adjustments did the trick and now everything is working brilliantly. I’m very happy with the result.

Here’s the code for anyone else who wants the SimpleNavigation macro to be sorted by date.

\define simple-navigation(tag:"demo", class, close:"no", sort:"title")
<$set name="tids" filter="[tag<__tag__>sort<__sort__>]">
<$list filter="[all[current]tag<__tag__>]">
<div class="$class$">
<$list filter="[enlist<tids>before<currentTiddler>]" variable="prevTiddler">
<$button to=<<prevTiddler>> tooltip=<<prevTiddler>> class="tc-btn-invisible $class$">🠈 Previous
<$list filter="[enlist<tids>before<currentTiddler>] [enlist<tids>after<currentTiddler>] +[count[]] -1">|</$list>
</$button>
</$list>
<$list filter="[enlist<tids>after<currentTiddler>]" variable="nextTiddler">
<$button to=<<nextTiddler>> tooltip=<<nextTiddler>> class="tc-btn-invisible $class$">Next 🠊
<$list filter="[<__close__>match[yes]]" variable=ignore><$action-sendmessage $message="tm-close-tiddler" $param=<<currentTiddler>>/></$list>
</$button>
</$list>
</div>
</$list>
\end

Yes, note that the tag tiddlers Tutorials and Pathways are both tagged Wizard. That’s all it takes. There is a configuration option for the sort field: $:/plugins/ScottSauyet/WizardNav/config, but I just realized that it’s global. If I ever get back to this, I could probably add an override for this in a field of the tag tiddler.

I’m not pushing this. It’s worked well for me. If it works for you, great. But I think you already have a solution you’re happy with.