Automatically make new pages appear first in sub-menu [solved]

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
memerson
Forum Members
Forum Members
Posts: 14
Joined: Mon Mar 23, 2009 5:03 pm

Automatically make new pages appear first in sub-menu [solved]

Post 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
Last edited by memerson on Fri Mar 27, 2009 12:45 pm, edited 1 time in total.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Automatically make new pages appear first in sub-menu (without reordering!)

Post 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...
JeremyBASS

Re: Automatically make new pages appear first in sub-menu (without reordering!)

Post 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
memerson
Forum Members
Forum Members
Posts: 14
Joined: Mon Mar 23, 2009 5:03 pm

Re: Automatically make new pages appear first in sub-menu (without reordering!)

Post 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
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Automatically make new pages appear first in sub-menu (without reordering!)

Post by Dr.CSS »

[solved] ?...
memerson
Forum Members
Forum Members
Posts: 14
Joined: Mon Mar 23, 2009 5:03 pm

Re: Automatically make new pages appear first in sub-menu (without reordering!)

Post 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!
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Automatically make new pages appear first in sub-menu [solved]

Post by Dr.CSS »

Maybe there is some sort of smarty to sort ascending that you can put in your menu template...
JeremyBASS

Re: Automatically make new pages appear first in sub-menu [solved]

Post 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
Last edited by JeremyBASS on Fri Mar 27, 2009 6:25 pm, edited 1 time in total.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Automatically make new pages appear first in sub-menu [solved]

Post by Dr.CSS »

Hmm solved but no explanation as to how, and this may actually help someone else...
User avatar
requish
Forum Members
Forum Members
Posts: 183
Joined: Sat Jan 24, 2009 3:12 pm

Re: Automatically make new pages appear first in sub-menu [s

Post 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.
Jean le Chauve

Re: Automatically make new pages appear first in sub-menu [s

Post 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
modifier.sort_object_array.zip
(549 Bytes) Downloaded 192 times
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
User avatar
requish
Forum Members
Forum Members
Posts: 183
Joined: Sat Jan 24, 2009 3:12 pm

Re: Automatically make new pages appear first in sub-menu [s

Post by requish »

Can I please for scripts for CMS 1.10?
Jean le Chauve

Re: Automatically make new pages appear first in sub-menu [s

Post 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.
Post Reply

Return to “The Lounge”