Page 1 of 1

Capture menu text

Posted: Sat Dec 17, 2005 10:15 am
by fadum
Hi

Is it possible to get the menu text of the current page's parent?

i really need this urgently but cant seem to find a way to do it.

I can get the current page with {menutext} but i need its highest parent

Many Thanks

Re: Capture menu text

Posted: Sun Dec 18, 2005 4:21 am
by Ted
Unfortunately, there is no quick way to do this.  We're working on a better solution.

In the meantime... (untested code, so it might need tweaking)

Code: Select all

global $gCms;
$menu_text = '';

#Get pageinfo object and current hierarchy
$paginfo =& $gCms->variables['pageinfo'];
$hierarchy =& $pageinfo->content_hierarchy;

#Take hierarchy and only find the first section of it
$parent = split('.', $hierarchy, 1);
$parent = $parent[0]; //Always returns an array

#Pad out the zeros so it matches what is stored in the db
$parent = str_pad($parent, 5, '0', STR_PAD_LEFT);

#Select that piece of content's menu text out of the database
$db =& $gCms->db;
$row =& $db->GetRow('select menu_text from ' . cms_db_prefix() . 'content where hierarchy = ?', array($parent));

#If there is a row returned, set the value
if (isset($row))
    $menu_text = $row['menu_text'];
Now the most straight forward answer, but it's the best we have right now.  The hierarchy manager changes that will most likely be in 0.11.2 will make it process much easier.

Re: Capture menu text

Posted: Sun Dec 18, 2005 10:04 am
by fadum
1.Typo of "paginfo"
2.It wouldnt seem to split, so i changed to explode

Works Just Great Now! Thanks Wishy!

Re: Capture menu text

Posted: Sun Dec 18, 2005 12:52 pm
by Ted
Ah, yes, explode would be the right one.  Glad it's working...

Re: Capture menu text

Posted: Wed Apr 05, 2006 5:13 pm
by fadum
This no longer seems to work with the latest version, do you have another way please

Thanks