Page 1 of 1

Automatically list subcategories on parent page

Posted: Sat Nov 07, 2009 12:54 pm
by mvandiermen
Is there any code I can use to automatically list subcategories on parent page.

Re: Automatically list subcategories on parent page

Posted: Sat Nov 07, 2009 1:06 pm
by Jos
Subcategories of what?

Or do you mean a list of the children of a page? See User Defined Tag: http://wiki.cmsmadesimple.org/index.php ... rrent_page

Re: Automatically list subcategories on parent page

Posted: Sat Nov 07, 2009 1:45 pm
by mvandiermen
Yes I meant children of a page.  I was working on the News module when I posted the question. 

Thank you, that is exactly what I needed.

For anyone who wants to do this;

1. go to: Expentions > User Defined Tages

Create tag called subpages

Code: Select all

global $gCms;
$manager =& $gCms->GetHierarchyManager();
$thisPage = $gCms->variables['page_name'];
$currentNode = &$manager->sureGetNodeByAlias($thisPage);

$nodes = $currentNode->getChildren();

if ($currentNode->hasChildren()) {
  echo '<ul class="sectionlinks">';
  foreach ($nodes as $node) {
     $content= $node->getContent();
     $url = $content->GetURL();
    if ($url == "#") { /* section header has no link by default */
      $url = "index.php?page=".$content->Alias();
    }
    echo "<li><a href=\"".$url."\">".$content->MenuText()."</a> </li>";

  }
  echo "</ul>";
}


2.
Add {subpages} to your parent page contents

Re: Automatically list subcategories on parent page

Posted: Sat Nov 07, 2009 1:51 pm
by calguy1000
It amazes me the amount of effort people will go to to NOT read the help....
MenuManager does this already.

Re: Automatically list subcategories on parent page

Posted: Thu Jan 07, 2010 9:08 pm
by fiddler
While this is useful to a point, I've been searching the forum/wiki/etc. to take this a couple of steps farther.  I think I've come upon the solution, but I don't understand how to implement it (need baby step instructions, I guess).

What I want to show on the parent page is not merely display the "list" of children, but to show the title of the page, the thumbnail associated with that page, a block of content (special decription) of the page, and a "read more" link that goes to each child page.

I believe the answer on how to do this lies somewhere in the CGSimpleSmarty module (which I've installed) - using some of the following code:

get_children([$alias],[$showinactive],[$assign])
Return an array containing information about a pages children (if any)

Arguments:
[$alias] - (optional) The page alias to test. If no value is specified, the current page is used.
[$showinactive] - (optional) Wether inactive pages should be included in the result (defaults to false).
[$assign] - (optional) The name of a variable to assign the results to.

Fields:

alias - the page alias of the child
id - the page id of the child
title - the page id of the child
menutext - the menu text of the child

Example:
{$cgsimple->get_children('','',$children)}
{if count($children)}
   {foreach from=$children item='child'}
      {if $child.show_in_menu}
        Child:  id = {$child.id} alias = {$child.alias}
      {/if}
   {/foreach}
{/if}
   
get_page_content($alias,[$block],[$assign])
Returns the text of a specific content block of another page.

Arguments:
$alias - The page alias to extract content from.
[$block] - (optional) The name of the content block in the specified page. if this variable is not specified, 'content_en' is assumed.
[$assign] - (optional) The name of a variable to assign the results to.

Example:
The title of the current page is {$cgsimple->get_page_title()}


However, I am clueless as to what it actually means so I can create/implement the code as it should be.
I've read the Smarty manual, but only came away bug-eyed.
I don't know if I need to put Smarty data or logic that is specific to each child page - and if I do, I don't know what that data or logic would be. 

Can some kind guru enlighten me?