GetSimple Support Forum
QUESTION Displaying child pages on the same page as parent - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: General Questions and Problems (http://get-simple.info/forums/forumdisplay.php?fid=16)
+--- Thread: QUESTION Displaying child pages on the same page as parent (/showthread.php?tid=6629)



Displaying child pages on the same page as parent - tomslominski - 2014-08-09

Hi. I'm considering using GetSimple for a site. Let's imagine I have a navigation structure like so:

- Home page
-- Sub page 1
-- Sub page 2
-- Sub page 3
- Another page
-- Another sub page 1
-- Another sub page 2
-- Another sub page 3

What I want to do, is use GetSimple to generate links for pages Home page and Another page, and then display those pages together with their children. For example, when the user goes to the home page, they would see the content of the home page, but also divs with the content of sub page 1, sub page 2 and sub page 3 below it, like so:

[Image: 18-05-05.png]

Would this be at all possible with GetSimple? I'd imagine it would have to be a bit like the WordPress loop, where on every parent the children are looped and displayed in a div, but I've never used GetSimple before, so I don't really know what is possible.


RE: Displaying child pages on the same page as parent - Everyone - 2014-08-09

Here. You want to check out getChildrenMulti() where "options" are actually the fields with data that you want to have returned. This function also works with custom fields added by other plugins like the "I18N Custom Fields" plugin.


RE: Displaying child pages on the same page as parent - tomslominski - 2014-08-09

That looks like it could work perfectly Smile From my understanding of WordPress (the two seem similar), I understand I'd be using that on the template page?


RE: Displaying child pages on the same page as parent - Carlos - 2014-08-09

Can be done using the I18N plugin. I think that the Child Menu plugin would work too (but it doesn't support all types of permalink structures AFAIK)

You could also use something like this in your template:

PHP Code:
<?php foreach (getChildren(return_page_slug()) as $child): ?>
 <a href="<?php echo find_url($childreturn_page_slug()); ?>"><?php getPageField($child'title'); ?></a>
 <br />
<?php endforeach; ?>



RE: Displaying child pages on the same page as parent - shawn_a - 2014-08-09

not menu, content.

working code for this is actually posted somewhere in the forum I believe.


RE: Displaying child pages on the same page as parent - Carlos - 2014-08-09

oops

so something like this?
PHP Code:
<?php foreach (getChildren(return_page_slug()) as $child): ?>
  <div class="subpage">
   <?php getPageContent($child); ?>
  </div>
<?php endforeach; ?>



RE: Displaying child pages on the same page as parent - shawn_a - 2014-08-09

yes or something like
not sure if this returns a assoc array or not
PHP Code:
$page get_page_slug(false);
foreach(
getChildrenMulti($page,array('content'))) as $key=>$value){
echo 
$value;



although i would use a plugin like custom fields or something since files have to be loaded for each content as page cache is not used.


RE: Displaying child pages on the same page as parent - shawn_a - 2014-08-09

idea for plugin that adds content to pages.xml for small sites that use pages like this.
Ill probably just add this to core though as an option to cacheall

carlos, does that template syntax work in php 5.2 ?


RE: Displaying child pages on the same page as parent - Carlos - 2014-08-09

I think that syntax is available since PHP 4.


RE: Displaying child pages on the same page as parent - D.O. - 2020-04-03

Hi GetSimplers, meanwhile someone made a great work about "getChildrenMulti" function!!!

http://dimayakovlev.ru/notebook/gruppirovka-i-filtraciya-vyvoda-stranic-po-godu-publikacii-v-getsimple-cms/

I tried one these PHP script and it works fine! Useful.


RE: Displaying child pages on the same page as parent - Felix - 2020-04-04

Hi D.O.

Thanks for posting this code.

I translated it from russian to english:

==================================

Working with sets of pages with different reciprocal relationships is fundamental when designing a website
that contains a significant amount of content.

The following snippet of PHP code can be used to display a list of child pages of the current page
in GetSimple CMS 3.4. For example, to build a list of subpages of a section.

<?php $page = get_page_slug ( false ); $children = getChildren ( $page ); echo '<ul>' ; foreach ( $children as $child ) { $url = generate_url ( $child ); echo '<li><a href="' . $url . '">' . returnPageField ( $child , 'title' ) . '</a></li>' ; } echo '</ul>' ; ?>

For code compatibility with GetSimple CMS 3.3, replace the call to the generate_url() function with find_url() :

$url = find_url ( $child , $page );

<?php $page = get_page_slug ( false ); $children = getChildren ( $page ); echo '<ul>' ; foreach ( $children as $child ) { $url = find_url ( $child ); echo '<li><a href="' . $url . '">' . returnPageField ( $child , 'title' ) . '</a></li>' ; } echo '</ul>' ; ?>

To use the code, you must place its call in the component or file of the page design template.


RE: Displaying child pages on the same page as parent - D.O. - 2020-04-10

Welldone, Felix!
I'm wondering if this russian author is an user who we know here.


[quote='Hi D.O.

Thanks for posting this code.

I translated it from russian to english' pid='68119' dateline='1585923747']