Modify The WordPress Pages Widget to Include Pages Instead of Exclude Pages
Posted by alex in Insights at 7:02 AMRecently I was setting up a WordPress blog and needed to use the default pages widget to list a certain set amount of pages. On this blog I used the NextGEN Gallery for dozens of different galleries. The issue was that I wanted to only list a couple of pages using the default Pages widget and when using NGG I would have dozens if not hundreds of pages that I would need to exclude with the default Pages widget. So what I needed to do was include a couple of page ID’s instead of excluding hundreds of page ID’s.
The problem above can be accomplished by making one minor adjustment to one WordPress file. We will need to modify the wp_pages_widget PHP function to include the pages specified in the admin versus excluding them.
File to Modify: <wp-root-directory>/wp-includes/widgets.php
Line: 682
Replace The Below:
$out = wp_list_pages( array('title_li' => '', 'echo' => 0, 'sort_column' => $sortby, 'exclude' => $exclude) );
With:
$out = wp_list_pages( array('title_li' => '', 'echo' => 0, 'sort_column' => $sortby, 'include' => $exclude) );
Notice you only modify one exclude with include. Do not change each instance! So now whatever Page ID’s you enter into the “Exclude” configuration box under the Pages Widget will be included instead of excluded. If you want to also modify the below line in the same file to display Include in the Pages Widget instead of Exclude.
File: <wp-root-directory>/wp-includes/widgets.php
Line: 734
Replace:
<label for="pages-exclude"><?php _e( 'Exclude:' ); ?> <input type="text" value="<?php echo $exclude; ?>" name="pages-exclude" id="pages-exclude" cla ss="widefat" /></label>
With:
<label for="pages-exclude"><?php _e( 'Include:' ); ?> <input type="text" value="<?php echo $exclude; ?>" name="pages-exclude" id="pages-exclude" cla ss="widefat" /></label>
Again the only thing you are changing out is Exclude: with Include:.
Some people may search for the wp_list_pages function to accomplish the same goal but I found it much easier to modify the wp_pages_widget since it will be rare for me to ever use the wp_list_pages PHP function again.
- WordPress: Display Pages Marked Private To All Users When I was initially attempting to do this it was...
- Modify WordPress Admin Plugin To Display As A WP Admin Dashboard Widget Previously I wrote an article that detailed modifying the WordPress...
- WordPress Mandigo Theme: Modify The Order Of The Header Navigation Menu One of my favorite themes for WordPress is the Mandigo...
- Create A New WordPress Admin Page And Add It To The WP Admin Menu After a recent issue I ran across I decided I...
- Modify WordPress Plugin Shashin Default Thumbnail Size I have been using the Shashin WordPress plugin for awhile...
Tags: exclude, function, include, NextGen Gallery, NGG, page ID, PHP, WordPress, wp_list_pages, wp_pages_widget
























Entries (RSS)
PHP as a technology has gained enterprise acceptance.
thanks for your post. It was helpful.
[Reply]
alex Reply:
May 6th, 2009 at 12:32 PM
Glad it helped out.
[Reply]
Thank you Man!!
[Reply]
alex Reply:
January 19th, 2010 at 12:38 PM
Hello Samsó,
Sure man… no problem. Glad the article helped you out.
Thanks.
alex
[Reply]
updating wordpress changes will be lost?
[Reply]
alex Reply:
June 18th, 2010 at 7:38 AM
Hello Mic3000,
Not sure I understand the question you are asking…. If you could provide more details we will try to provide an answer.
Thanks.
alex
[Reply]