Navigator: is there a simple way to reverse the array?

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
Andrew Prior
Forum Members
Forum Members
Posts: 247
Joined: Sun Oct 28, 2007 4:14 am

Navigator: is there a simple way to reverse the array?

Post by Andrew Prior »

In CMSMS 2.1.2:
Site will add 50 to 60 articles per year in several areas of the site... is it possible to set Navigator to list menu items last to first instead of the default first to last, so that the last item added is always at the top of the list?
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm

Re: Navigator: is there a simple way to reverse the array?

Post by Jeff »

calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Navigator: is there a simple way to reverse the array?

Post by calguy1000 »

Yes....

{$nodes=array_reverse($nodes)}
directly before the foreach loop should reverse the list of everything.

You may need to enable permissive smarty in the config.php
(it's in the config reference doc).
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Andrew Prior
Forum Members
Forum Members
Posts: 247
Joined: Sun Oct 28, 2007 4:14 am

Re: Navigator: is there a simple way to reverse the array?

Post by Andrew Prior »

Thankyou.
As a complete amateur, I can insert the smarty code into the template, and I have enabled the permissive smarty in config.php which allows the template to load.

But I have no idea how to configure the reverse array function so that Calguy's code actually does anything.

I have in Navigator
{Navigator start_level="4" collapse="1" ... ion test"}
which works as intended, except it does not reverse the array.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Navigator: is there a simple way to reverse the array?

Post by velden »

Code: Select all

...
{if !isset($depth)}{$depth=0}{/if}

{if isset($nodes)}{strip}
{$nodes=array_reverse($nodes)} 
<ul>
  {foreach $nodes as $node}
    {if $node->type == 'sectionheader'}
...
Andrew Prior
Forum Members
Forum Members
Posts: 247
Joined: Sun Oct 28, 2007 4:14 am

Re: Navigator: is there a simple way to reverse the array

Post by Andrew Prior »

Thank you all. It works when I have this as the last few lines of the Navigator template

Code: Select all

{/strip}{/function}
{$nodes=array_reverse($nodes)}
{if isset($nodes)}
{Nav_menu data=$nodes depth=0}
{/if}
Last edited by Andrew Prior on Tue Apr 05, 2016 9:21 pm, edited 1 time in total.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Navigator: is there a simple way to reverse the array?

Post by velden »

Andrew Prior wrote:Thank you all. It works when I have this as the last few lines of the Navigator template

Code: Select all

{/strip}{/function}
{$nodes=array_reverse($nodes)}
{if isset($nodes)}
{Nav_menu data=$nodes depth=0}
{/if}
Better change order of those two lines for obvious reason:

Code: Select all

{/strip}{/function}
{if isset($nodes)}
{$nodes=array_reverse($nodes)}
{Nav_menu data=$nodes depth=0}
{/if}
Andrew Prior
Forum Members
Forum Members
Posts: 247
Joined: Sun Oct 28, 2007 4:14 am

Re: Navigator: is there a simple way to reverse the array?

Post by Andrew Prior »

Ta... How can I apply [Solved] to the original post? It doesn't seem to let me edit it?
Post Reply

Return to “The Lounge”