• Is there a way to specify depth in when using get_pages?
    when one uses wp_list_pages, you can specify: depth=1

    I want to show the children of 246, but not 246’s grandchildren.

    I assure you, there is a very good reason indeed for me using get_pages and not wp_list_pages.

    The function that does the depth action is
    function _page_level_out

    I can’t really get my head around the logic so as to apply to my get_pages.

    Help?

    This is my code:

    `
    $kids = get_pages(“child_of=246”);
    foreach ($kids as $post) {
    $kinder = get_object_vars($post);
    $cptitle = $kinder[post_title];
    $kinder = $kinder[ID];

    note: the last line of code gets mangled when I post it. it just echos the info and closes the foreach.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter crisispictures

    (@crisispictures)

    The answer has got something to do with this bit–

    if ( $page->post_parent != $page->ID)
    $page_tree[$page->post_parent][‘children’][] = $page->ID;

    dull gray brain porridge is starting to ooze out of my left ear.

    I am not sure if you figured this out yet… after so many months… ?? but i thought i would post this for future searchers like myself, since i was looking for the same thing and your post was my key.

    Just wanted to clear it up.

    Same idea as above code:

    <?php
    $page_id = $wp_query->post->ID;

    $pages = get_pages(“child_of=246”);

    foreach ($pages as $page) :
    if ($page->post_parent == $page_id) :

    $entry = get_object_vars($post);
    $e_title = $entry[post_title];
    $e_id = $entry[ID];
    $e_guid = $entry[guid];
    $e_name = $entry[post_name];
    $e_content = $entry[post_content];
    ?>
    <div id=”item_content”>
    <h1>“><?php echo ($e_title); ?></h1>
    <?php echo apply_filters(‘the_content’, $e_content); ?>
    <?php edit_post_link(‘Edit this entry.’, ”, ”); ?>
    </div>

    <?php
    endif;
    endforeach;
    ?>

    The important line is the if statement. It tells it to only use pages that have the same parent ID as the current page’s ID. Thus skipping any grandchildren.

    I added in some other things that you can do with get_pages. pretty handy. Almost create your own loop but with pages. Nice for an online store possibly?

    Let me know if you have any questions on that. I might have missed something.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_pages’ is closed to new replies.