Get parent title? code from FAQ page doesn't work.

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
Benek

Get parent title? code from FAQ page doesn't work.

Post by Benek »

I'm using the latest 1.4.1 version of CMSMS. I'm trying to use this code (in a user-defined tag) to get the title of parent page:

Code: Select all

global $gCms;
$db =& $gCms->GetDb();

$vars =& $gCms->variables;

$query = "SELECT content_name FROM "
  .cms_db_prefix()
  ."content WHERE content_id = (SELECT parent_id FROM "
  .cms_db_prefix()
  ."content WHERE content_id = '"
  .$vars['content_id']
  ."');";

$dbresult = $db->Execute($query);
if ($dbresult && $dbresult->RowCount() > 0) {
  $row = $dbresult->FetchRow();
  echo $row['content_name'];
} else {
  echo $vars['pageinfo']->content_menutext;
}
Which I found on http://wiki.cmsmadesimple.org/index.php/FAQ/Layout_and_Design/SubMenu_Heading

But it doesn't work. It gives the following error:
Fatal error: Call to undefined function: rowcount() in ...my domain...../lib/content.functions.php(854) : eval()'d code on line 15
Could anyone point me to a bit of code that will do the same thing and work in 1.4.1?

Even better, what I really need, is this function to echo the parent title if (and only if) the page it's on is at a certain level. For example, if the page is on level 3 I want to get the title of it's parent (level 2). But if the page in question is already at level 2 then I want it to just return the current page's title rather then the parents. So basically it's always showing the level 2 title regardless of whether the page is on level 2 or anything deeper.

Could someone help me out with that? I'd be very grateful.

Thanks.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Get parent title? code from FAQ page doesn't work.

Post by Dr.CSS »

OK I have 3, so you name them what you want and call them in the tag, maybe I should put these in the wiki...

I called it alias hence the alias in tag...

tag {alias assign="root_page_alias"}{$root_page_alias}

global $gCms;
global $smarty;

$manager =& $gCms->GetHierarchyManager();

$var = 'root_page_alias';
if( isset($params['assign']) && $params['assign'] != '' )
{
 $var = $params['assign'];
}
$result = "NO RESULT";
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
while( isset($currentNode) && $currentNode->getLevel() >= 0 )
{
   $currentContent =& $currentNode->getContent();
   $result = $currentContent->alias();
   $currentNode =& $currentNode->getParentNode();
}
$smarty->assign($var,$result);



next...

I called it nextup...

tag  {nextup assign="parent_page_alias"}{$parent_page_alias}

global $gCms;
global $smarty;

$manager =& $gCms->GetHierarchyManager();

$var = 'parent_page_alias';
if( isset($params['assign']) && $params['assign'] != '' )
{
 $var = $params['assign'];
}
$result = "NO RESULT";
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
while( isset($currentNode) && $currentNode->getLevel() >= 1 )
{
   $currentContent =& $currentNode->getContent();
   $result = $currentContent->alias();
   $currentNode =& $currentNode->getParentNode();
}
$smarty->assign($var,$result);

And this one gets the menutext so you can change the parameter to parent or root to get the menu text you want, parent or root...

tag, red is the name you give it...

hmmm not sure on this one? {menutext assign="parent_page_menutext"}{$parent_page_menutext}

global $gCms;
global $smarty;

$manager =& $gCms->GetHierarchyManager();

$var = 'root_page_menutext';
if( isset($params['assign']) && $params['assign'] != '' )
{
 $var = $params['assign'];
}
$result = "NO RESULT";
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
while( isset($currentNode) && $currentNode->getLevel() >= 0 )
{
   $currentContent =& $currentNode->getContent();
   $result = $currentContent->menutext();
   $currentNode =& $currentNode->getParentNode();
}
$smarty->assign($var,$result);

Sorry bout this last one but I can't find where I used it.... :(

EDIT: I figured it out, I use it to print out the Menu Text of the parent page...  DUH...
Last edited by Anonymous on Tue Nov 17, 2009 3:12 am, edited 1 time in total.
Benek

Re: Get parent title? code from FAQ page doesn't work.

Post by Benek »

Hey thanks these look great! I'm sure one of them will work for me. You are such a big help Mark!

Just one quick question:

For the first one "alias" I'm assuming it's going to get the info from the level 1 parent of that page. If I want it to get the level 2 parent (assuming the page it was on was level 3 or more), would I just change the line:

while( isset($currentNode) && $currentNode->getLevel() >= 0 )

to increase the level?
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Get parent title? code from FAQ page doesn't work.

Post by Dr.CSS »

You don't change that part, if the 3rd level is from the same parent as the 2nd level, or is child of 2, then use the root page one it goes to the top, root, of the current page...

If it's not in the same page structure not sure what you would do...
Benek

Re: Get parent title? code from FAQ page doesn't work.

Post by Benek »

Hey Mark thanks again. Your first tag "alias" worked perfectly for me with one small modification.
Cheers  ;D
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Get parent title? code from FAQ page doesn't work.

Post by calguy1000 »

CGSimpleSmarty module has a method for this.

It's simple.
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.
blissofbeing

Re: Get parent title? code from FAQ page doesn't work.

Post by blissofbeing »

calguy1000 wrote: CGSimpleSmarty module has a method for this.

It's simple.
That would probably be:

Code: Select all

{$cgsimple->get_root_alias('','root_alias')}{$cgsimple->get_page_title($root_alias)}
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Get parent title? code from FAQ page doesn't work.

Post by Dr.CSS »

Well that I wouldn't know, I'm not a programmer, those are something I had from before CGSimpleSmarty module...

Thanks...

EDIT: well it turns out I had used something like this in the past but it was in a menu template...

http://forum.cmsmadesimple.org/index.ph ... #msg112125
Last edited by Anonymous on Sat Sep 13, 2008 8:11 am, edited 1 time in total.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Get parent title? code from FAQ page doesn't work.

Post by Dr.CSS »

@blissofbeing

I tried that for getting the root parent alias and it ate my CSS?...

used like so, class="{$cgsimple->get_root_alias('','root_alias')}{$cgsimple->get_page_title($root_alias)}"  must not be the way to use it...
artisites
Forum Members
Forum Members
Posts: 12
Joined: Mon Jan 12, 2009 9:43 pm

Re: Get parent title? code from FAQ page doesn't work.

Post by artisites »

This is a thread bump!

I've installed the CGSimpleSmarty module, and it works a treat to display my parent title on chilren pages.

However, when it is on the parent page it doesn't display anything (Because it is a root parent i guess)

What smarty code would I use to instruct it to say If parent display title, if chld display parent alias?
artisites
Forum Members
Forum Members
Posts: 12
Joined: Mon Jan 12, 2009 9:43 pm

Re: Get parent title? code from FAQ page doesn't work.

Post by artisites »

in the meantime i have assigned an extra attribute to the parent page so it reads that.
artisites
Forum Members
Forum Members
Posts: 12
Joined: Mon Jan 12, 2009 9:43 pm

Re: Get parent title? code from FAQ page doesn't work.

Post by artisites »

also, when it displays the parent alias, this often has "-" hyphens in the title, so rather than say "Kit Contents" it just says "kit-contents" which isn't so pretty.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Get parent title? code from FAQ page doesn't work.

Post by calguy1000 »

Smarty is a programming language.  It's a macro language that is 1/2 way between html and php.

Just like any scripting language (wether that be html(xml), php, C++ or assembly) you have to understand how things work, read AND UNDERSTAND the documentation (too many people just skim it and then still plead for help) and until you know what you're doing, go in baby steps.

And then, when you have problems, you still have to go back to making baby steps.... that means changing 1 small thing at a time, inspecting it to make sure it's right, then moving forward.

So

1st.  Read the smarty documentation, and keep it up when you're doing something.... if you need to know how to do something, read the smarty documents there's lots in there.  (particularly when asking questions like:  how do I do this IF the value of this variable IS EQUAL TO 'that').

AND test every step.

I could give you the answer to your question, but quite honestly, experience tells me that if I did, you or somebody else would be back within minutes for the answer to the next trivial question.... They are trivial, honestly.
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.
Locked

Return to “CMSMS Core”