Hello.
I would like to be able to get a recursive array of the children of a page. This would be much like $cgsimple->get_children except that it would need to include children of children (ie grand children, great grand children etc).
So in the following example (which is fictitious):
1 Home
2 About
2.1 Who we are
2.2 Mission
2.2.1 Vision
the children of About are:
-Who we are
-Mission
-Vision.
[EDIT] Using the UDT that Peciura created (see below) works slightly different. It takes a hierarchical position to find the children are (in example: using the structure above, get the children of page #2, not about). It returns page aliases. It will also include the page itself, in example: if you said to get the children of page 2, you would get these aliases in the array (assuming the navigation structure above): about, who-we-are, mission, vision.
Thanks in advance.
Isaac.
Get recursive list of children [SOLVED]
Get recursive list of children [SOLVED]
Last edited by isaacd on Sun Feb 28, 2010 4:21 am, edited 1 time in total.
Re: Get recursive list of children
As another approach, is it possible to get all the pages that have "1" as the first number in the hierarchical position? The logic would be something like this:
$position >= 1 && $position < 2
In other words, get all the pages that have a hierarchical position that is greater than or equal to one, but also less than 2.
This would accomplish essentially the same thing as my first post (get children recursive).
I have heard of something called the hierarchy manager, but have found no documentation of it at all, and thus have no clue how to use it.
Thanks
Isaac.
$position >= 1 && $position < 2
In other words, get all the pages that have a hierarchical position that is greater than or equal to one, but also less than 2.
This would accomplish essentially the same thing as my first post (get children recursive).
I have heard of something called the hierarchy manager, but have found no documentation of it at all, and thus have no clue how to use it.
Thanks
Isaac.
Re: Get recursive list of children
You could start with UDT "all_content"
Look what it outputs
Code: Select all
/*$params['assign']*/
if (!empty($params['assign'])){
global $gCms;
$contentops =& $gCms->GetContentOperations();
$assign = $contentops->GetAllContent(false);
$smarty = $gCms->GetSmarty();
$smarty->assign($params['assign'], $assign);
}
Code: Select all
{all_content assign='all_content'}
<pre>
{$all_content|var_dump}
</pre>
Re: Get recursive list of children
Okay, well I've got that, but I don't know quite what to do from there. What I am looking for is an array of all the aliases that have a position of greater than or equal to one, but less than two. So if I had this structure:
1 Home
-- 1.1 About
---- 1.1.1 Our Founders
---- 1.1.2 Our Future
--1.2 Mission
2 Calendar
Then I should have these aliases in the array:
home
about
our-founders
our-future
mission
Thanks.
Isaac.
1 Home
-- 1.1 About
---- 1.1.1 Our Founders
---- 1.1.2 Our Future
--1.2 Mission
2 Calendar
Then I should have these aliases in the array:
home
about
our-founders
our-future
mission
Thanks.
Isaac.
Re: Get recursive list of children
Try to modify UDT "all_content" as follows:
Use it
Code: Select all
/*$params['assign']*/
/*$params['parent_hierarchy']*/
if (!empty($params['assign']) && !empty($params['parent_hierarchy'])){
global $gCms;
$contentops =& $gCms->GetContentOperations();
$all_content = $contentops->GetAllContent(false);
$assign = array();
foreach($all_content as $one_page){
if (strpos($one_page->mHierarchy, $params['parent_hierarchy']) === 0){
$assign[] = $one_page->mAlias;
}
}
$smarty = $gCms->GetSmarty();
$smarty->assign($params['assign'], $assign);
}
Code: Select all
{all_content assign='all_content' parent_hierarchy='00001'}
<pre>
{$all_content|var_dump}
</pre>
Re: Get recursive list of children
That worked well. Thanks Peciura.