Last active
August 29, 2015 14:03
-
-
Save joliveras/938cba1da36185807434 to your computer and use it in GitHub Desktop.
Function for create a shortcode to display subpages
This file contains 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 function childpages_shortcode( $atts ) { | |
global $post; | |
$args = array( | |
'post_parent' => $post->ID, | |
'post_type' => 'page', | |
'depth' => 1, | |
'orderby' => 'menu_order', | |
'order' => 'ASC' | |
); | |
$childpages .= '<ul>'; | |
$loop_subpag = new WP_Query($args); | |
if( $loop_subpag->have_posts() ): | |
while( $loop_subpag->have_posts() ): $loop_subpag->the_post(); | |
$childpages .= '<li>' . get_the_title() . '</li>'; | |
endwhile; | |
endif; | |
$childpages .= '</ul>'; | |
wp_reset_postdata(); | |
return $childpages; | |
} | |
add_shortcode( 'childpages', 'childpages_shortcode' ); ?> |
Hi can use conditionals inside the loop with the substr
function http://php.net/manual/en/function.substr.php
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How could this be edited so that in the shortcode, you can specify to only show pages that have a title that starts with an "A", "B", or "C"? Is this possible?