Page 1 of 1

List children at parent page, and get position (hierarchy)

Posted: Wed Feb 29, 2012 9:31 pm
by brrods
Hi there, I need to build an index page of all children pages (of a given page), and I need to grab the position of each child so that I can use it to grab external content related to that.

Example

Page structure:
1. Portfolio
1.1 Item 1
1.2 Item 2
1.3 Item 3

I need to grab the link to that page (alrealdy done, but I can“t get the position --> 1.1 (i.e.). Have tried {$child.position} {$child.hierarchy}, but nothing prints out.

Here is the code:

Code: Select all

{$cgsimple->get_children('','','children')}
{if count($children)}
{foreach from=$children item='child'}
<div>
[color=#FF8040][b]{$child.hierarchy}{$child.id}[/b][/color]
{cms_selflink page=$child.alias}
</div>

{/foreach}
{/if}
Again, I need to get the position "1.1", "1.2", "1.3" of children pages and list them at parent page.

Any ideas are appreciated :D

Thanks!

Re: List children at parent page, and get position (hierarch

Posted: Wed Feb 29, 2012 10:34 pm
by calguy1000
try this:

Code: Select all

{menu childrenof=$page_alias assign='junk'}
<pre>{$nodelist|@print_r}</pre>

Re: List children at parent page, and get position (hierarch

Posted: Thu Mar 01, 2012 1:12 pm
by brrods
Hi Calguy, thanks.

Do I have to invoke the menu tag so that I can use {$child.hierarchy}?

I am using MLEcms module to build a big website and I had to create over 60 picture gallerys, which I did using CGSmartImage together with fancybox, as shown in an example in the module documentation :).

The pictures however needed to apear in both portuguese and english pages, and as I didn't want to duplicate then, I put all images in folders called x.2.1.3.1, x.2.1.3.2, and so on... Than I grab the page position, split it and change the first character for x, so the portuguese page which is 1.2.1.3.1 generates a variable x.2.1.3.1 and the english page which is 2.2.1.3.1 also generates the same variable. It works pretty well :) Now for building the index page which will list all those pages I thought of doing something like this:

Code: Select all

{$cgsimple->get_children('','','children')}
{if count($children)}
{foreach from=$children item='child'}
{assign var="var" value=$child.hierarchy} --> this doesn't work
{assign var="bar_at" value=$var|strpos:"."}
{capture assign=path}uploads/images/energia/obras/x.{$var|substr:$bar_at+1}/fotos/destaque.jpg{/capture}
{assign var='file' value=$path|glob}
<div class="portfolio-box left" style="width:210px; height:130px;">
{CGSmartImage src=$file filter_croptofit='150,100' title='' alt=''}
{cms_selflink page=$child.alias}
</div>

{/foreach}
{/if}
The thing is that the pages are marked not to show in menu (they are a lot of pages and the menu sit at the left side of the website), so therefore I didn't use the menu module or created a menu template. (Is it possible to create a menu even if the pages are marked not to show in menu?)

Do you think it will work with the above code? How could I grab the child hierarchy inside a {foreach}?

Thanks!

Re: List children at parent page, and get position (hierarch

Posted: Fri Mar 02, 2012 7:48 am
by uniqu3
brrods wrote:(Is it possible to create a menu even if the pages are marked not to show in menu?)
Look in MenuManager help, you will find a parameter show_all='1' which will show also pages that are marked to not show in menu.

Re: List children at parent page, and get position (hierarch

Posted: Wed Mar 21, 2012 10:42 pm
by brrods
Thanks CalGuy and Uniqu3.

Just for the record, I ended up doing it like this:

1. I've created folders with pictures numbered x.1.2.3 (following page hierarchy replacing the first character for "x" since I am using MLE and the pages in diferent languages differ only in that first character).

2. I've created an UDT named get_position:

Code: Select all

global $gCms;
$manager =& $gCms->GetHierarchyManager();
$thisPage = $params['page_alias'];
$node = &$manager->sureGetNodeByAlias($thisPage);
$content= $node->getContent();
$position = $content->Hierarchy();
echo $position;
3. I then list the content of subpages in a template, automatically grabing the correct picture for each child, which is inside the respective folder, and works for all languages without having to repeat them. I have used CGSimple and I automatically resize the pictures creating thumbs with CGSmartImage.

Code: Select all

{$cgsimple->get_children('','false','children')}
{if count($children)}

{foreach from=$children item='child'}
{capture assign="position"}{get_position page_alias=$child.alias}{/capture}
{assign var="var" value=$position}
{assign var="bar_at" value=$var|strpos:"."}
{capture assign=path}uploads/images/energia/obras/x.{$var|substr:$bar_at+1}/destaque/*.jpg{/capture}
{assign var='files' value=$path|glob}
<div class="portfolio">
{if count($files)}
	{foreach from=$files item='file'}
	{assign var='filename' value='/'|explode:$file}
	{if $filename[6]|truncate:6:"" != 'thumb_' }
	{CGSmartImage src=$file filter_croptofit='100,120' title='' alt='' class="left"}
	{/if}
	{/foreach}
{/if}
{cms_selflink page=$child.alias}
</div>
{/foreach}
{/if}
Well, I am pretty sure that there is an easier better way to do it, but I had to solve it the same day, so... Anyway, ideas still welcome as optimizing is always good.

For the record, each child portfolio page creates an image gallery with fancybox and CGSmartImage, works pretty good, also repecting MLE structure without having to repeat the pictures in the server (using de idea of x.1.2.3 folders). Like this:

Code: Select all

{assign var="var" value=$position}
{assign var="bar_at" value=$var|strpos:"."}
{capture assign=path}uploads/images/energia/obras/x.{$var|substr:$bar_at+1}/fotos/*.jpg{/capture}
{assign var='files' value=$path|glob}
{if count($files)}
<h3>{MleCMS name="snippet_Fotos"}</h3>
<div class="gallery">
{foreach from=$files item='file'}
{assign var='filename' value='/'|explode:$file}
{if $filename[6]|truncate:6:"" != 'thumb_' }
<a rel='simple_album' class="fancybox" href="{CGSmartImage src=$file filter_resize='h,500' notag=1 noembed=1}">{CGSmartImage src=$file filter_croptofit='150,100' title='' alt=''}</a>
{/if}
{/foreach}
</div>
{/if}
Don'f forget to activate fancybox.

Thanks :)

Re: List children at parent page, and get position (hierarch

Posted: Mon Apr 09, 2012 4:59 pm
by brrods
Hi CalGuy, at this code listed above I need to reverse the order of CGSimpleSmarty get_children function.

I need to list the children in DESC order.

Is it possible? Even if I have to change the module's core, since I use it only for this.

Thank you in advance.