Automatically list subcategories on parent page

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.
Post Reply
mvandiermen
Forum Members
Forum Members
Posts: 83
Joined: Mon Nov 03, 2008 1:28 pm

Automatically list subcategories on parent page

Post by mvandiermen »

Is there any code I can use to automatically list subcategories on parent page.
Jos
Support Guru
Support Guru
Posts: 4020
Joined: Wed Sep 05, 2007 8:03 pm

Re: Automatically list subcategories on parent page

Post 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
mvandiermen
Forum Members
Forum Members
Posts: 83
Joined: Mon Nov 03, 2008 1:28 pm

Re: Automatically list subcategories on parent page

Post 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
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Automatically list subcategories on parent page

Post by calguy1000 »

It amazes me the amount of effort people will go to to NOT read the help....
MenuManager does this already.
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.
fiddler

Re: Automatically list subcategories on parent page

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

Return to “CMSMS Core”