Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LOOP function through children posts
#1
Hi,

This is a feature that I think would be great to add to the GS core.

A loop function in the admin/basic/theme_functions.php to loop through all the pages that are children of some parent.

The $LANG appended to the GSDATAPAGESPATH is a remnant of a previous post:
http://get-simple.info/forum/topic/2965/...-the-code/

A functional demo of this loop can be observed at:
http://getsimple.mechantdesign.com/en_US/videos/

Code:
function loop($parent = null) {
global $LANG;
$path = GSDATAPAGESPATH . $LANG . '/';
$dir_handle = opendir($path) or die("Unable to open $path");
  $filenames = array();
  while ($filename = readdir($dir_handle)) {
     $filenames[] = $filename;
}
  closedir($dir_handle);
  
    $count="0";
    $pagesArray = array();
    if (count($filenames) != 0) {
        foreach ($filenames as $file) {
            if ($file == "." || $file == ".." || is_dir($path . $file) || $file == ".htaccess"  ) {
                // not a page data file
            } else {
                $data = getXML($path . $file);
                if ($data->private != 'Y' && $data->parent == $parent) {
                    $pagesArray[$count] = $data;
                    $count++;
                }
            }
        }
    }
    return $pagesArray;
}

Please let me know what you think of this.

Thank you.
Reply
#2
what would be the advantage, which purpose do you think ?


If you suggest something, you should describe why it could be helpful ;=)

ok, I understand:
Quote:to loop through all the pages that are children of some parent.

you want the children of a page to show subpages ...
that is already there, like n00dles101 pointed to
|--

Das deutschsprachige GetSimple-(Unter-)Forum:   http://get-simple.info/forums/forumdisplay.php?fid=18
Reply
#3
Version 3.1 comes with the function

Code:
$pages=getChildren($page); // returns an array of slugs of the children of the supplied page
My Github Repos: Github
Website: DigiMute
Reply
#4
@Connie, yes I agree, I should describe better. I think it was just too evident... to myself.

@n00dles, it's more than just getting the children slugs.


I've actually updated my example: http://getsimple.mechantdesign.com/.

The point of the loop is to return pages as object to be able to display any of there attributes. Say you would like your homepage to display all your "News" pages. But not displaying them fully, just their excerpt + a link to the full text.

In order to do so, to use the loop, many theme functions should be twitched like this:

Code:
function get_page_excerpt($n=200, $html=false, $content=false) {
    if (!isset($content)) global $content;

Where $content remains by default the page's global content, but in the context of a loop, would become what has been provided.

Calling the loop would look like this:

Code:
<?php global $LANG; ?>
<?php foreach (loop('videos') as $p) { ?>
<div class="post">
    <h3><a href="<?php echo (find_url($p->url, $p->parent, 'full', $LANG)); ?>"><?php echo $p->title; ?></a></h3>
    <?php get_page_excerpt(200, false, $p->content); ?>
</div>
<?php }; ?>

The whole idea of this loop is to introduce the abstract distinction between posts/and pages. A $limit variable could also be added to the loop() function to return only the 3 most recent News for example.

It's just a way to make a parent page more dynamic, very similar to WordPress I should say.
Reply
#5
There is a second function which accepts an array of parameters you want returned

Code:
getChildrenMulti($page,array());

So your code above could be written as.

Code:
<?php global $LANG; ?>
<?php foreach (getChildrenMulti($page,array('parent','url','title')) as $p) { ?>
<div class="post">
    <h3><a href="<?php echo (find_url($p->url, $p->parent, 'full', $LANG)); ?>"><?php echo $p->title; ?></a></h3>
    <?php get_page_excerpt(200, false, returnPageContent($p->url)); ?>
</div>
<?php }; ?>

Mike.
My Github Repos: Github
Website: DigiMute
Reply
#6
Well then,
problem solved I should say!
Reply
#7
Thanks for the suggestion by the way... never said...

GS3.1 has lots of new functionality which makes this sort of stuff a bit easier to do.

the new caching functions can be found in the wiki here.

http://get-simple.info/wiki/config:caching-function

I'm in the process of documenting them fully and will upload when they are complete..
My Github Repos: Github
Website: DigiMute
Reply
#8
Oh, btw.

What do you think of the get_page_excerpt() modification?

Even the 3.1 getChildrenMulti() you mentionned, there's no way to make use of the theme functions at the present time... right?
Reply




Users browsing this thread: 1 Guest(s)