Lately one in every of our customers requested us learn how to show baby pages of a WordPress Web page? Usually when engaged on a website that has pages with baby pages, chances are you'll need to present these baby pages on the guardian web page in a sidebar widget or one other location in your template. On this article, we'll present you learn how to show an inventory of kid pages for a guardian web page in WordPress.
To see an instance of an inventory of kid pages on guardian web page, see the screenshot beneath that we have now from OptinMonster’s How it Works page. You may also see this in use on Tagwp’s Blueprint page.
Earlier than we get begin, for individuals who usually are not accustomed to Youngster Pages, please try our information on the difference between Posts and Pages in WordPress. One of many essential function of pages is that they are often hierarchical. Which means a web page can turn out to be a guardian web page and has baby pages (i.e sub-pages) beneath it. This lets you group totally different pages collectively beneath one guardian web page. For instance, if in case you have a Product Web page on a web site, then you'll be able to add pages similar to Options, Pricing, and Help as baby pages. Every baby web page can have its personal baby pages as properly.
Video Tutorial
Should you don’t just like the video or want extra directions, then proceed studying.
To create a baby web page, merely create or edit a web page in WordPress such as you would usually do. Beneath the Web page Attributes meta field, select a guardian web page from the drop down menu.
Word: If you don't see the Web page Attributes menu, then please click on on the Display screen Choices button on the highest proper hand nook of your display screen. It'll show a menu the place it's worthwhile to make it possible for Web page Attributes is checked.
Displaying Youngster Pages on the Guardian Web page in WordPress
To checklist baby pages beneath a guardian web page, it's worthwhile to add the next code in a site-specific plugin, or in your theme’s functions.php file:
perform wpb_list_child_pages() add_shortcode('wpb_childpages', 'wpb_list_child_pages');
The code above first checks to see if a web page has a guardian or the web page itself is a guardian. If it's a guardian web page, then it shows the kid pages related to it. If it's a baby web page, then it shows all different baby pages of its guardian web page. Lastly, if that is only a web page with no baby or guardian web page, then the code will merely do nothing. Within the final line of the code, we have now added a shortcode, so you'll be able to simply show baby pages with out modifying your web page templates.
To show baby pages merely add the next shortcode in a web page or textual content widget within the sidebar:
[wpb_childpages]
In some circumstances, your theme is probably not able to execute shortcodes in a textual content widget. If it's not working, then see this tutorial on how to use shortcodes in WordPress sidebar widgets.
Dynamically Show Youngster Pages With out Any Shortcode
Utilizing shortcode is handy, however the issue with utilizing shortcodes is that you'll have to add shortcode in all pages which have guardian or baby pages. Chances are you'll find yourself having shortcodes in a number of pages, and generally chances are you'll even neglect so as to add the shortcode.
A greater method can be to edit the web page template file in your theme, in order that it may robotically show baby pages. To do this it's worthwhile to edit the primary web page.php
template or create a custom page template in your theme.
In your web page template file, it's worthwhile to add this line of code the place you need to show baby pages.
<?php wpb_list_child_pages(); ?>
That’s all. Your theme will now robotically detect baby pages and show them.
If you're utilizing guardian pages with a number of baby pages which have their very own baby pages, then the WordPress admin view can get complicated. For a greater technique to arrange guardian and pages attempt utilizing admin column view.
We hope this text helped you checklist baby pages in WordPress. Tell us if in case you have any questions or suggestions by leaving a remark beneath.
Supply: Thomas Griffin