1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

display all child and gran and gran gran child of page id 10

Discussion in 'WordPress' started by macaela, Sep 9, 2015.

  1. #1
    Hi
    I have query to display all child page of ID 10, but I would also like to display granchildren, gran gran gran children of that page ID 10

    this what I have so far
    Thank you


    'orderby' => 'date',
    'order' => 'DESC',
    'post_parent' => 10,
    'post_type' => 'page',
    'meta_key' => 'extra_menu',
    'meta_value' => 'portfoliomenu',
    'showposts' => $posts));
     
    macaela, Sep 9, 2015 IP
  2. freelance varma

    freelance varma Greenhorn

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #2
    Hi, please try this

    Add to functions.php

    /**
    * Create HTML list of pages.
    *
    * @package Razorback
    * @subpackage Walker
    * @author Michael Fields <>
    * @copyright Copyright (c) 2010, Michael Fields
    * @license http://opensource.org/licenses/gpl-license.php GNU Public License
    *
    * @uses Walker_Page
    *
    * @Since 2010-05-28
    * @alter 2010-10-09
    */
    class Razorback_Walker_Page_Selective_Children extends Walker_Page {
    /**
    * Walk the Page Tree.
    *
    * @global stdClass WordPress post object.
    * @uses Walker_Page::$db_fields
    * @uses Walker_Page::display_element()
    *
    * @Since 2010-05-28
    * @alter 2010-10-09
    */
    function walk( $elements, $max_depth ) {
    global $post;
    $args = array_slice( func_get_args(), 2 );
    $output = '';

    /* invalid parameter */
    if ( $max_depth < -1 ) {
    return $output;
    }

    /* Nothing to walk */
    if ( empty( $elements ) ) {
    return $output;
    }

    /* Set up variables. */
    $top_level_elements = array();
    $children_elements = array();
    $parent_field = $this->db_fields['parent'];
    $child_of = ( isset( $args[0]['child_of'] ) ) ? (int) $args[0]['child_of'] : 0;

    /* Loop elements */
    foreach ( (array) $elements as $e ) {
    $parent_id = $e->$parent_field;
    if ( isset( $parent_id ) ) {
    /* Top level pages. */
    if( $child_of === $parent_id ) {
    $top_level_elements[] = $e;
    }
    /* Only display children of the current hierarchy. */
    else if (
    ( isset( $post->ID ) && $parent_id == $post->ID ) ||
    ( isset( $post->post_parent ) && $parent_id == $post->post_parent ) ||
    ( isset( $post->ancestors ) && in_array( $parent_id, (array) $post->ancestors ) )
    ) {
    $children_elements[ $e->$parent_field ][] = $e;
    }
    }
    }

    /* Define output. */
    foreach ( $top_level_elements as $e ) {
    $this->display_element( $e, $children_elements, $max_depth, 0, $args, $output );
    }
    return $output;
    }
    }

    Add to any template file with a php extension:

    $walker = new Razorback_Walker_Page_Selective_Children();
    wp_list_pages( array(
    'title_li' => '',
    'walker' => $walker,
    ) );

    Will recognize the child_of parameter.

    $walker = new Razorback_Walker_Page_Selective_Children();
    wp_list_pages( array(
    'title_li' => '',
    'child_of' => 1283,
    'walker' => $walker,
    ) );
     
    freelance varma, Sep 9, 2015 IP
  3. macaela

    macaela Active Member

    Messages:
    181
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
     
    macaela, Sep 15, 2015 IP
  4. macaela

    macaela Active Member

    Messages:
    181
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    Hi Thanks for taking the time to try help but unfortunally it didnt work only display the lits of direct child it doesn't display granchild of id 10
     
    macaela, Sep 15, 2015 IP