Ask me a question at the Wordpress Ninja Forum
How To Create A New Section Of ‘Pages’ And Have The Links Populate Automatically
Posted on August 7, 2008
Filed Under Wordpress Solutions |
Ok, so i thought i’d mention this one as i had someone request it before. Basically the example here is for a case where you may want to add a seperate section of Wordpress Pages that does not show up under the ‘Pages’ section in the sidebar (About, Contact us, etc.), but rather a seperate section of pages.
Let’s take a site about Soccer, for example. I have my standard Wordpress Pages such as ‘About’, ‘Contact Me’, ‘Privacy Policy’ etc but i also want another section of Pages under these in the sidebar about my favorite soccer teams. I want to be able to create a Wordpress Page (as opposed to a ‘Post’) about each of my favorite soccer teams and have them appear under a heading of ‘My Favorite Teams’. Here’s what you need to do:
Edit your sidebar.php file and find the part where it references the pages i.e. This line will be contained within a section like this:
<?php wp_list_pages(’title_li=Pages’ ); ?>
Make sure all your pages have already been created, then find out what each page ID is - make a seperate note of these. You can find the page IDs by going into WP-ADMIN>MANAGE>PAGES and hovering over each page - note the ‘post=X’ number at the end of the page’s url at bottom of your browser’s status bar - that ‘X’ number is the page id of the page. So you would make the code look something like this:
<?php wp_list_pages(’include=a,b,c&title_li=Pages’ ); ?>
<?php wp_list_pages(’include=x,y,z&title_li=My Favorite Teams’ ); ?>
What you are essentially doing here is splitting the pages into 2 sections - ‘Pages’ and ‘My Favorite Teams’, telling it explicitly which pages are to be included in each of those sections. So for example if i wanted to include pages 1, 2 and 3 in the ‘Pages’ section my code would be:
<?php wp_list_pages(’include=1,2,3&title_li=Pages’ ); ?>
and then in the ‘My Favorite Teams’ section i can include all the team pages i want, referring to the list of Page IDs i made previously - lets say for example pages with ID’s of 6,9,11,12,15. Here is the code for that.
<?php wp_list_pages(’include=6,9,11,12,15&title_li=My Favorite Teams’ ); ?>
Save the sidebar.php file and upload it to your host server, overwriting the original - of course make sure you have backups just in case.
The only downside to doing this procedure is that you need to manually keep your pages updated. If you add a new Team Page down the track in the example above then you need to find the page ID and then add it into the code. So a bit of ongoing housekeeping, but that’s the price to pay for a cool customization ![]()
Comments
One Response to “How To Create A New Section Of ‘Pages’ And Have The Links Populate Automatically”
Leave a Reply
Related Posts:
Hi, i am the Wordpress Ninja. My name is Paul and my goal is to be able to answer everyone's Wordpress questions (for free) and post the best solutions on this blog. So for all questions and issues please post in the
Nice site Paul
You could also use what you have above for the a,b,c.. but then for the Favorite Teams one you could use:
wp_list_pages(’exclude=a,b,c&title_li=My Favorite Teams’ );
That way, you don’t have to keep updating your code as you add pages.
(at least i’m pretty sure that would work.. haven’t tested)