How Do I Create a Subpage List in WordPress?
Creating a subpage list in WordPress is easy. First, create a new file called “subpages.
php” and place it in your WordPress root directory. Then, add the following code to the file:.
‘About Us’, ‘contact’ => ‘Contact Us’, ‘blog’ => ‘Blog’, ‘category’ => ‘Categories’, ‘posts’ => ‘Posts’, ); // Add a page template to the list of subpage links function subpage_template() { return array( ‘title’ => __( ‘Subpage %s’, ‘my-site’ ), ‘content’ => get_page_content( ‘subpage’ ), ); } // Add a list of page templates to the list of subpage links function subpage_templates() { return array( ‘about’ => ‘About Us’, ‘contact’ => ‘Contact Us’, ‘blog’ => ‘Blog’, ‘category’ => ‘Categories’, ‘posts’ => ‘Posts’, ); } // Add a list of pages to the list of subpage links function subpage_pages() { return $subpages; } // Add the list of subpage links to the list of pages function add_subpage_links() { $pages = array( ‘about’ => ‘About Us’, ‘contact’ => ‘Contact Us’, ‘blog’ => ‘Blog’, ‘category’ => ‘Categories’, ‘posts’ => ‘Posts’, ); $subpages = array( ‘about’ => ‘About Us’, ‘contact’ => ‘Contact Us’, ‘blog’ => ‘Blog’, ‘category’ => ‘Categories’, ‘posts’ => ‘Posts’, ); $pages[‘subpage’] = $subpages; return $pages; } // Add the list of pages to the list of subpage links function add_page_links() { $pages = array( ‘about’ => ‘About Us’, ‘contact’ => ‘Contact Us’, ‘blog’ => ‘Blog’, ‘category’ => ‘Categories’, ‘posts’ => ‘Posts’, ); $subpages = array( ‘about’ => ‘About Us’, ‘contact’ => ‘Contact Us’, ‘blog’ => ‘Blog’, ‘category’ => ‘Categories’, ‘posts’ => ‘Posts’, ); $pages[‘subpage’] = $subpages; return $pages; } // Add the list of page templates to the list of page links function add_page_templates() { $pages = array( ‘about’ => ‘About Us’, ‘contact’ => ‘Contact Us’, ‘blog’ => ‘Blog’, ‘category’ => ‘Categories’, ‘posts’ => ‘Posts’, ); $subpages = array( ‘about’ => ‘About Us’, ‘contact’ => ‘Contact Us’, ‘blog’ => ‘Blog’, ‘category’ => ‘Categories’, ‘posts’ => ‘Posts’, ); $pages[‘subpage’] = $subpages; return $pages; } // Return the list of pages return add_subpage_links(), add_page_links(), subpage_templates(), page_templates(); ?>
In the code above, we are creating a list of subpage links and a list of page templates. We are also adding a list of pages to the subpage links list and a list of page templates to the page links list.
Finally, we are returning the list of pages.
Now, you can create pages using the page templates and subpage links list. For example, you can create a new page called “About Us” using the “about” page template and the subpage links list.