Ticket #1277 (assigned enhancement)

Opened 3 years ago

Last modified 8 months ago

Extend is_page() to support child_of and decendent_of

Reported by: astorm Assigned to: westi (accepted)
Priority: normal Milestone: 2.9
Component: Template Version: 2.1
Severity: normal Keywords: dev-feedback 2nd-opinion
Cc:

Description

To be able to identify whether a page is child_of another page or a decendent_of another page.

Let's say I have a bunch of pages that has "Articles" page (id=3) as the parent. I use is_page('child_of=3') in my menu/navigation system to highlight that section.

Attachments

1277_seperate_functions.diff (1.6 kB) - added by leflo on 09/29/06 14:10:29.
multiple functions: is_child_of_page, is_decendent_of_page. (backward compatible)
1277_is_page.diff (2.2 kB) - added by leflo on 09/29/06 17:01:33.
1277_is_page.2.diff (2.5 kB) - added by leflo on 09/30/06 17:47:40.
Now backward compatible

Change History

04/23/05 02:02:45 changed by astorm

  • Patch set to No.

06/30/05 04:42:07 changed by markjaquith

  • keywords set to bg|needs-patch.

This should probably be given consideration.

09/29/06 14:10:29 changed by leflo

  • attachment 1277_seperate_functions.diff added.

multiple functions: is_child_of_page, is_decendent_of_page. (backward compatible)

09/29/06 14:14:24 changed by leflo

  • keywords changed from bg|needs-patch to bg|needs-patch, has-patch.
  • milestone set to 2.1.

My favorit would be the extension of is_page. Please comment on the patches.

09/29/06 14:18:14 changed by leflo

forgot: for 1277_is_page.diff is_page would be called like is_page('id=3') or is_page('descendent_of=3') or even is_page('id=3&descendent_of=3'), which would OR both queries.

is_page supports: id, child_of, descendent_of, parent_of, ancestor_of.

09/29/06 14:27:51 changed by westi

$results = $wpdb->get_results("SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'page'");

I don't like the scalability implications of this.

Can you not switch the patch to do specific queries for the different request types so as to ensure that the SQL request is bounded small enough?

This may make decendent_of stuff harder to work out - can it use any of the walker classes that exist as well?

09/29/06 16:35:46 changed by foolswisdom

  • keywords changed from bg|needs-patch, has-patch to has-patch.

Either needs-patch or has-patch ;-)

09/29/06 16:53:30 changed by leflo

Scalability: Ok, I changed it a bit, now you only get that query if you really need it (descendent_of, ancestor_of), and parent_of has its own query now. Anyhow, that query isn't expensive (at least for < 500 pages and espacally in contrast to the query for get_pages()), the other option would be to do n queries (n = depth) or do some very tricky SQL substatements (which would kill all MySQL 4 support). (Could it be better to use get_pages() since it is/could be cached?)

Walker Classes: Why? I don't really walk the tree, it's more like zipping through a list.

09/29/06 17:01:33 changed by leflo

  • attachment 1277_is_page.diff added.

09/30/06 11:33:16 changed by markjaquith

Unless I'm mistaken, this patch kills backwards compatibility for:

is_page(1)

is_page('about')

You should move that old code above your parse_str() call, so those still work.

Matching by name/slug of descendants or ancestors would be nice, but at least keep current capabilities implemented.

09/30/06 17:47:40 changed by leflo

  • attachment 1277_is_page.2.diff added.

Now backward compatible

09/30/06 17:48:57 changed by leflo

Ok, it is now backward compatible. Hope you like it now. :)

11/29/06 22:42:55 changed by matt

  • milestone changed from 2.1 to 2.2.

02/15/07 22:09:30 changed by rob1n

  • keywords changed from has-patch to has-patch dev-feedback.
  • owner changed from anonymous to rob1n.
  • version changed from 1.5.1 to 2.1.
  • status changed from new to assigned.

+1. But maybe a variable/argument to turn on/off returning true if it's a child/parent page?

02/20/07 06:09:40 changed by rob1n

  • owner deleted.
  • status changed from assigned to new.

03/10/07 04:35:14 changed by rob1n

  • owner set to rob1n.
  • status changed from new to assigned.

03/18/07 01:36:50 changed by rob1n

  • keywords changed from has-patch dev-feedback to dev-feedback 2nd-opinion.

I've got two methods to tackling this. (Well, 3, since one can be done in two ways...)

1. Seperate functions. You can call is_page() to know if that page is the current page, and then also call is_page_child() to find out whether the current page is a child of X page. Also, is_page_descendant(). So, example:

if (is_page(2) is_page_child(21)) would return true if the current page is either ID 2, or a child of page 21.

2. An argument to achieve the same as method 1. Either have a single is_page() argument that can be either what it is now (ID, page title, etc.), but can also be a query string so you can return true also if it's a child or descendant of another page. The other way of doing this is just having separate arguments.

I'm torn.

03/18/07 01:37:00 changed by rob1n

  • owner deleted.
  • status changed from assigned to new.

03/27/07 19:46:26 changed by foolswisdom

  • milestone changed from 2.2 to 2.3.

09/05/07 19:25:42 changed by foolswisdom

  • milestone changed from 2.3 to 2.4 (next).

12/27/07 21:53:12 changed by santosj

  • component changed from General to Template.

12/28/07 08:57:33 changed by westi

  • owner set to westi.
  • status changed from new to assigned.

02/12/08 09:05:31 changed by pishmishy

  • milestone changed from 2.5 to 2.6.

Bumping milestone for feature freeze.