Created
September 3, 2020 06:59
-
-
Save maheshwaghmare/7921ad00133ab3a2f6c58ea12c5ba2b6 to your computer and use it in GitHub Desktop.
List all the pages in list with `[child_pages_list]` shortcode in WordPress.
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
| <?php | |
| add_shortcode( 'child_pages_list', function() { | |
| $args = array( | |
| 'post_parent' => get_the_ID(), | |
| 'post_type' => get_post_type(), | |
| ); | |
| $posts = get_children( $args ); | |
| ob_start(); | |
| if( $posts ) { | |
| ?> | |
| <ul> | |
| <?php foreach( $posts as $single_post ) { ?> | |
| <li><a href="<?php echo get_permalink( $single_post->ID ); ?>"><?php echo $single_post->post_title; ?></a></li> | |
| <?php } ?> | |
| </ul> | |
| <?php | |
| } | |
| return ob_get_clean(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment