Make WordPress Core

Opened 16 years ago

Closed 16 years ago

#1669 closed enhancement (fixed)

Patch to "wp_list_pages" to add the opposite of "exclude" (called "only")

Reported by: Fryfrog Owned by: markjaquith
Milestone: 2.1 Priority: normal
Severity: normal Version: 1.5.2
Component: General Keywords: exclude, only, opposite bg|has-patch bg|dev-feedback bg|squashed
Focuses: Cc:

Description

The diff below will add the opposite functionality of "exclude" to the wp_list_pages. This means instead of excluding all but 1 page, you can choose to ONLY show that one page. This way, no matter what you add in the future it will never have to be messed with to exclude it.

--- wp-includes/template-functions-post.php.old 2005-09-11 09:02:35.000000000 -0400
+++ wp-includes/template-functions-post.php 2005-09-11 08:56:30.000000000 -0400
@@ -287,6 +287,20 @@

}

}

}

+ if (!empty($ronly?)) {
+ $onlypages = preg_split('/[\s,]+/',$ronly?);
+ if (count($onlypages)) {
+ foreach ($onlypages as $onlypage) {
+ if (!empty($exclusions)) {
+ $exclusions .= ' OR ';
+ } else {
+ $exclusions .= ' AND ';
+ }
+ echo $onlypages[$onlypage];
+ $exclusions .= ' ID = ' . intval($onlypage) . ' ';
+ }
+ }
+ }

$pages = $wpdb->get_results("SELECT * " .

"FROM $wpdb->posts " .

Attachments (1)

1669.patch (1003 bytes) - added by skippy 16 years ago.
patched against 1.6 snapshot

Download all attachments as: .zip

Change History (8)

#1 @Fryfrog
16 years ago

Added it into a code block to make its formatting "nicer"

--- wp-includes/template-functions-post.php.old 2005-09-11 09:02:35.000000000 -0400
+++ wp-includes/template-functions-post.php     2005-09-11 08:56:30.000000000 -0400
@@ -287,6 +287,20 @@
                        }
                }
        }
+       if (!empty($r['only'])) {
+               $onlypages = preg_split('/[\s,]+/',$r['only']);
+               if (count($onlypages)) {
+                       foreach ($onlypages as $onlypage) {
+                               if (!empty($exclusions)) {
+                                       $exclusions .= ' OR ';
+                               } else {
+                                       $exclusions .= ' AND ';
+                               }
+                               echo $onlypages[$onlypage];
+                               $exclusions .= ' ID = ' . intval($onlypage) . ' ';
+                       }
+               }
+       }

        $pages = $wpdb->get_results("SELECT * " .
                                                                                                      "FROM $wpdb->posts " .

#2 @ryan
16 years ago

  • Milestone changed from 1.5.2 to 1.6

#3 @markjaquith
16 years ago

  • Keywords bg|has-patch bg|dev-feedback added
  • Owner changed from anonymous to markjaquith
  • Status changed from new to assigned

Thanks! I can't tell you how many people have asked me if this was possible.

@skippy
16 years ago

patched against 1.6 snapshot

#4 @skippy
16 years ago

  • Keywords bg|squashed added

#5 @mikelietz
16 years ago

Works for me.

#6 @matt
16 years ago

  • Milestone changed from 1.6 to 2.1

#7 @MichaelH
16 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

This ticket is resolved by changeset:3655 that added the ability to include a selected page or pages in function get_pages(). So, with wp_list_pages(), a parameter of 'include=3,4' will present just pages IDs 3 and 4.

Guess it's okay to change this to fixed even though it is assigned to Mark, and request bg's mark as Closed.


Note: See TracTickets for help on using tickets.