www.question-defense.com | Engage: Visit :: Login :: Register
Translate to English Übersetzen Sie zum Deutsch/German Переведите к русскому/Russian Μεταφράστε στα ελληνικά/Greek Vertaal aan het Nederlands/Dutch ترجمة الى العربية/Arabic 中文翻译/Chinese Traditional 中文翻译/Chinese Simplified 한국어에게 번역하십시오/Korean 日本語に翻訳しなさい /Japanese Traduza ao Português/Portuguese Traduca ad Italiano/Italian Traduisez au Français/French Traduzca al Español/Spanish
0

Recently 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.

DeliciousStumbleUponDiggTwitterMixxTechnoratiFacebookNews VineLinkedInYahoo! Bookmarks
Related posts:
  1. WordPress: Display Pages Marked Private To All Users When I was initially attempting to do this it was...
  2. Modify WordPress Admin Plugin To Display As A WP Admin Dashboard Widget Previously I wrote an article that detailed modifying the WordPress...
  3. WordPress Mandigo Theme: Modify The Order Of The Header Navigation Menu One of my favorite themes for WordPress is the Mandigo...
  4. Create A New WordPress Admin Page And Add It To The WP Admin Menu After a recent issue I ran across I decided I...
  5. Modify WordPress Plugin Shashin Default Thumbnail Size I have been using the Shashin WordPress plugin for awhile...

Tags: , , , , , , , , ,
7 Responses to “Modify The WordPress Pages Widget to Include Pages Instead of Exclude Pages”
  1. php development says:

    PHP as a technology has gained enterprise acceptance.

    thanks for your post. It was helpful.

    [Reply]

    alex Reply:

    Glad it helped out.

    [Reply]

  2. Samsó says:

    Thank you Man!!

    [Reply]

    alex Reply:

    Hello Samsó,

    Sure man… no problem. Glad the article helped you out.

    Thanks.
    alex

    [Reply]

  3. Mic3000 says:

    updating wordpress changes will be lost?

    [Reply]

    alex Reply:

    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]

  4.  
Leave a Reply