Capture menu text

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
fadum

Capture menu text

Post 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
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: Capture menu text

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

Re: Capture menu text

Post by fadum »

1.Typo of "paginfo"
2.It wouldnt seem to split, so i changed to explode

Works Just Great Now! Thanks Wishy!
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: Capture menu text

Post by Ted »

Ah, yes, explode would be the right one.  Glad it's working...
fadum

Re: Capture menu text

Post by fadum »

This no longer seems to work with the latest version, do you have another way please

Thanks
Locked

Return to “CMSMS Core”