Last active
March 19, 2019 13:36
-
-
Save kisildev/5fcba80eb1f8589a4b295137d849f434 to your computer and use it in GitHub Desktop.
Child pages. Subpages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Way 1. | |
| <?php if (have_posts()) : ?> | |
| <?php while (have_posts()) : the_post(); | |
| global $post; | |
| $parent_page = wp_get_post_parent_id(get_the_ID()); ?> | |
| <?php $arg = array( | |
| 'post_type' => 'page', | |
| 'order' => 'ASC', | |
| 'orderby' => 'title', | |
| 'posts_per_page' => -1, | |
| 'post_parent' => $parent_page, | |
| 'post__not_in' => array(get_the_ID()) | |
| ); ?> | |
| <section class="child-pages"> | |
| <div class="grid-container grid-container--lg"> | |
| <div class="grid-x grid-padding-x"> | |
| <div class="cell"> | |
| <h4 class="child-pages__header"><?php _e('Vi kan også helpe deg med', 'foundation'); ?></h4> | |
| </div> | |
| <?php $the_query = new WP_Query( $arg ); | |
| if ( $the_query->have_posts() ) : ?> | |
| <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?> | |
| <?php if (is_page() && $post->post_parent == $parent_page): ?> | |
| <div class="cell medium-6 large-4"> | |
| <div class="child-pages__item"> | |
| <a href="<?php the_permalink(); ?>" class="child-pages__link"> | |
| <h5 class="child-pages__title"><?php the_title(); ?></h5> | |
| </a> | |
| </div> | |
| </div> | |
| <?php endif ?> | |
| <?php endwhile; ?> | |
| <?php endif; wp_reset_query(); ?> | |
| </div> | |
| </div> | |
| </section> | |
| <?php endwhile; ?> | |
| <?php endif; ?> | |
| //https://stackoverflow.com/questions/45869998/displaying-first-level-parent-and-co-children-of-that-parent-page |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment