- <?php
- /*********************************
- *** Pagechecker - Parent/Child ***
- *********************************/
- $is_child = false;
- $has_ancestors = false;
- $enable_back = false;
- /* If "$post->post_parent" value is 0, the page is a top level page */
- if( is_page() && $post->post_parent > 0 ) {
- $is_child = true;
- $has_ancestors = true;
- $enable_back = true;
- $ancestors = get_ancestors( $post->ID, 'page' );
- $ancestor_url = get_permalink($ancestors[0]);
- //print_r($ancestors);
- if ( is_page() && $depth > 1 ) {
- $enable_back = true;
- }
- }
- if ($is_child) {
- /* Page IS a Child */
- 'post_type' => 'page',
- 'posts_per_page' => -1,
- 'post_parent' => $post->post_parent,
- 'order' => 'ASC',
- 'orderby' => 'menu_order'
- );
- $child = new WP_Query( $args );
- if ( $child->have_posts() ) : ?>
- <div class="childpages list">
- <?php while ( $child->have_posts() ) : $child->the_post(); ?>
- <span id="parent-<?php the_ID(); ?>" class="parent-page">
- <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
- </span>
- <?php endwhile; ?>
- </div>
- <?php endif; wp_reset_query();
- } else {
- /* Page is NOT a child */
- /* Page has no childs */
- } else {
- /* Page has childpages */
- 'post_type' => 'page',
- 'posts_per_page' => -1,
- 'post_parent' => $post->ID,
- 'order' => 'ASC',
- 'orderby' => 'menu_order'
- );
- $parent = new WP_Query( $args );
- if ( $parent->have_posts() ) : ?>
- <div class="parent childpages list">
- <?php while ( $parent->have_posts() ) : $parent->the_post(); ?>
- <span id="parent-<?php the_ID(); ?>" class="parent-page">
- <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
- </span>
- <?php endwhile; ?>
- </div>
- <?php endif; wp_reset_query();
- }
- }
- ?>
- <?php if($has_ancestors && $enable_back) : ?>
- <div class="back">
- <span class="backlink"><a href="<?php echo $ancestor_url; ?>"><i class="fa fa-long-arrow-left" aria-hidden="true"></i> <?php echo get_the_title( $ancestors[0] ) ?></a></span>
- </div>
- <?php endif; ?>
Recent Pastes