0

I'm working on a Wordpress website. The below code shows the children pages of the current parent page that you're on.

//Set up the objects needed
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));

//Get children
$children = ($post->post_parent) ? get_page_children( $post->post_parent, $all_wp_pages ) :  get_page_children( $post->ID, $all_wp_pages );


//Build custom items 
foreach($children as $child){ 

?>

            <a style="text-decoration:none;" href="<?php echo get_permalink($child->ID); ?>" class="live-slider" title="#caption1">

            <div class="header-title"><?php echo get_the_title($child->ID); ?></div><br/>
            <div class="header-subtitle"><?php echo get_the_subtitle($child->ID); ?></div>

            </a>

}

The problem that i'm having at the moment is that I want to be able to show the child pages of a specific parent page on all parent pages.

For example, I have a parent page called Subscriptions which has 4 children pages. I want these 4 children pages to also appear on each other parent page using the same code above if possible.

4

1 回答 1

0

如果您知道页面ID,那么您可以使用 wp_list_pages( $args );

$args = array(
    'depth'        => 0,
    'show_date'    => '',
    'date_format'  => get_option('date_format'),
    'child_of'     => 'parent page id goes here',
    'exclude'      => '',
    'include'      => '',
    'title_li'     => __('Pages'),
    'echo'         => 1,
    'authors'      => '',
    'sort_column'  => 'menu_order, post_title',
    'link_before'  => '',
    'link_after'   => '',
    'walker'       => '',
    'post_type'    => 'page',
     'post_status'  => 'publish' 
);

$child_pages=wp_list_pages( $args );

注意:child_of (integer) 只显示单个Page的子页面;使用 Page 的 ID 作为值。请注意,child_of 参数还将获取给定 ID 的“孙子”,而不仅仅是其直接子代。默认为 0(显示所有页面)。

wp_list_pages

于 2013-09-09T06:21:12.053 回答