Page 1 of 1
Automatically make new pages appear first in sub-menu [solved]
Posted: Wed Mar 25, 2009 10:30 am
by memerson
Hi everyone
I'm getting to grips with the Smarty language and CMSMS now which is great because it allows me to develop my skills but there's one thing that I'd like to be able to do but cannot figure out how.
When I create a new page using a particular parent (in this case Recent Work) I'd like each newly added page to appear at the TOP of the submenu and not added at the bottom, as ideally I'd like the newest first. Now, I know you can do this in the admin by using the re-order pages arrows but this is slightly impractical with the amount of pages I'm likely to have soon so if there's a Smarty code or something that can automatically place new pages at the top of the submenu, that would be great.
Has anyone got any ideas?
Thanks in advance,
Michael
Re: Automatically make new pages appear first in sub-menu (without reordering!)
Posted: Wed Mar 25, 2009 4:23 pm
by Dr.CSS
You can also use the Reorder Pages link at the bottom to drag and drop the pages where needed, I don't know of any programmable way to do it, others may...
Re: Automatically make new pages appear first in sub-menu (without reordering!)
Posted: Wed Mar 25, 2009 5:28 pm
by JeremyBASS
one long way to do this is use the extra fields, and gain it via a UDT
then add this logic to your template
if extra field = 1
node
/if
if extra field != 1
node
/if
if you search thru the forum you'll find both...
Help this helps
Cheers
jeremyBass
Re: Automatically make new pages appear first in sub-menu (without reordering!)
Posted: Thu Mar 26, 2009 11:30 am
by memerson
Thanks for the help! However, I did find some code in the documentation in the end that will do this:
http://wiki.cmsmadesimple.org/index.php ... nu_Manager
under "inverse_menu".
Michael
Re: Automatically make new pages appear first in sub-menu (without reordering!)
Posted: Thu Mar 26, 2009 4:54 pm
by Dr.CSS
[solved] ?...
Re: Automatically make new pages appear first in sub-menu (without reordering!)
Posted: Fri Mar 27, 2009 11:37 am
by memerson
mark wrote:
[solved] ?...
Actually, no, not really. The code given on the link was no use, since obviously that person didn't know Smarty language very well (he was using commands not existent in Smarty) but I think I'm going to resign to using the reorder section. Thanks for everyone's help!
Re: Automatically make new pages appear first in sub-menu [solved]
Posted: Fri Mar 27, 2009 5:52 pm
by Dr.CSS
Maybe there is some sort of smarty to sort ascending that you can put in your menu template...
Re: Automatically make new pages appear first in sub-menu [solved]
Posted: Fri Mar 27, 2009 6:17 pm
by JeremyBASS
you could always create the menu in a UDT... then you can do what you ask... using
http://us.php.net/sort
or
http://us.php.net/manual/en/function.asort.php
and sort on creation date... that is a sure fire way, and really simple... plus I think there is a UDT close to this some where in here... I think I saw it...
@sort may work... but you'd need to pull the creation date in to...
{foreach from=$Wever|@sortby:$creationdate item=node}...
http://www.phpinsider.com/smarty-forum/ ... php?t=1079
by I don't think that is in the core...
Anyways... that will work...
Cheers
jeremyBass
Re: Automatically make new pages appear first in sub-menu [solved]
Posted: Fri Mar 27, 2009 6:28 pm
by Dr.CSS
Hmm solved but no explanation as to how, and this may actually help someone else...
Re: Automatically make new pages appear first in sub-menu [s
Posted: Fri Aug 24, 2012 3:14 pm
by requish
Hi
This
Code: Select all
{foreach from=$nodelist|@sortby:$creationdate item=node}
dont work at all. There is only long list of errors.
I need to sort nodes by datepost in my menu. Somebody can help with it? I using CMS 1.10.3.
Cheers.
Re: Automatically make new pages appear first in sub-menu [s
Posted: Tue Aug 28, 2012 7:48 am
by Jean le Chauve
Hi
I made a plugin modifier for sorting arrays of objects based on idea :
http://www.i-do-this.com/blog/69/Sortin ... in-foreach
Code: Select all
<?php
/**
* Smarty plugin
*/
/**
* Smarty sort_object_array modifier plugin
*
* Type: modifier
* Name: sort_object_array
* Help : http://www.cmsmadesimple.fr/forum/viewtopic.php?id=4439
* @link
* @author Jean le Chauve
* @param array
* @param string
* @return array
* put '-' before the value for inverse
*/
function smarty_cms_modifier_sort_object_array($objArray, $sortby='')
{
if (!is_array($objArray)) {
die("not array, you cannot use the modificator sort_object_array with this variable");
}
$dir = '>';
if ($sortby[0] == '-')
{
$sortby = substr($sortby, 1);
$dir = '<';
}
$cmp = create_function('$a,$b', 'return strtolower($a->'.$sortby.')'.$dir.'strtolower($b->'.$sortby.');');
usort($objArray, $cmp);
return $objArray;
}
?>
So, place this file under /plugins and name it modifier.sort_object_array or download it
Apply the modifier on your specific menu template who start on second level :
{foreach from=$nodelist|sort_object_array:'-created' item=node}
You can also use '-modified' for the latest modified pages.
'-' before value do the inverse sorting.
Beter help in french :
http://www.cmsmadesimple.fr/forum/viewtopic.php?id=4439
Re: Automatically make new pages appear first in sub-menu [s
Posted: Tue Aug 28, 2012 8:52 am
by requish
Can I please for scripts for CMS 1.10?
Re: Automatically make new pages appear first in sub-menu [s
Posted: Tue Aug 28, 2012 11:40 am
by Jean le Chauve
No, it is for cmsms 1.11
It is best to upgrade, if not today, it will do anyway one day or the other.