Display sub page list in WordPress parent page

If you want to display the sub page list link in the WordPress parent page, you can use the following code.

 Display sub page list in WordPress parent page Add the following code to the current topic functions.php:

 function wpb_list_child_pages() { global $post;  if ( is_page() && $post->post_parent ) $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' ); else $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' ); if ( $childpages ) { $string = '<ul>' . $ childpages . '</ul>'; } return $string; } add_shortcode('wpb_childpages', 'wpb_list_child_pages');

After that, you can use short codes:

 [wpb_childpages]

Add to the text widget.

The default text widget does not support short codes. You can set:

 add_filter('widget_text', 'do_shortcode');

Add to the current topic functions.php to enable the text widget to support short code.

You can also add the following code to the appropriate location of the theme page template:

 <? php wpb_list_child_pages(); ?>

For example, if you create a new page template and add code, you can only select the new page template when using this function.

 

Original text: How to Use Shortcodes in your WordPress Sidebar Widgets

Most of the articles on this site are original and used for personal learning records, which may be helpful to you, for reference only!

 weinxin
My Wechat
WeChat copied
Copyright Notice
Please indicate the source and link of the original article reprinted on this site. Thank you for your cooperation!
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 
 Robin
five hundred and ninety-eight million eight hundred and forty-five thousand and six
Comments two    Visitors two
    •  May's SEO blog
      May's SEO blog three

      I don't understand this very well. It would be more perfect if the blogger used pictures to show the effect~

      •  Don't want to log in
        Don't want to log in zero

        The function wpb_list_child_pages() in the page template is not displayed. It needs to be changed to echo wpb_list_child_pages() to display correctly.

       anonymous

      Comment

      Anonymous netizens
       :?:  :razz:  :sad:  :evil:  :!:  :smile:  :oops:  :grin:  :eek:  :shock:  :???:  :cool:  :lol:  :mad:  :twisted:  :roll:  :wink:  :idea:  :arrow:  :neutral:  :cry:  :mrgreen:

      Drag the slider to complete validation