Make WordPress Core

Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#2364 closed enhancement (duplicate)

Create is_page_or_child() Template Tag

Reported by: FireMotion Owned by:
Milestone: Priority: low
Severity: normal Version: 1.2
Component: Template Keywords: has-patch
Focuses: Cc:


Recursively determine if a page or one of its child pages is currently displayed.

Proposed usage

Returns true when Page 42 or one of its child pages is being displayed.

It would also help to include the "exclude" parameter.

To create code for dynamic/collapsable menu's more easily.

Current workaround
Part of the variable currently equals:

strpos(wp_list_pages('echo=0&exclude='.$exclude.'&child_of='.$page_id), 'current_page_item') !== FALSE

But this only includes the child pages, not the page with $page_id itself.

Attachments (1)

is_page_or_child.diff (1.0 KB) - added by leflo 11 years ago.

Download all attachments as: .zip

Change History (7)

#1 @davidhouse
12 years ago

  • Resolution set to invalid
  • Status changed from new to closed

You can already do is_page(42). Not sure if that works for child pages.

#2 @FireMotion
12 years ago

  • Keywords tag menu page added
  • Priority changed from normal to low
  • Resolution invalid deleted
  • Severity changed from normal to enhancement
  • Status changed from closed to reopened
  • Summary changed from Create is_current() Template Tag to Create is_page_or_child() Template Tag

Maybe it should be something like is_page_or_child('42'):

Example: A menu with a lot of subpages, but only the current pages' navigation should be expanded, the others should be collapsed:

  • About

--- Who

  • Download

--- UpgradeGuide
--- DownloadGuide

  • Tutorial


  • Support
  • Development

Let's say that "UpgradeGuide" is the current page. Therefore, it should look like this:

  • About [Collapsed]
  • Download [Expanded]

--- UpgradeGuide
--- DownloadGuide [Collapsed]

  • Tutorial

Forum [Collapsed]

1) First get all the top navigation items for the pages (wp_list_pages('depth=1')).
2) Explode that list as an array, then for each item, determine if it should display the submenu items.

How would one easily determine if it should retrieve (wp_list_pages) all the subnavigation/listpages for "Download" or not? Because is_page('Download') returns false, as the actual page is "UpgradeGuide," not "Download."

#3 @FireMotion
12 years ago

Menu's in previous post should read:

- About
--- Who
- Download
--- UpgradeGuide
--- DownloadGuide
----- DownloadTroubleshooting
- Tutorial
- Support
- Development


- About ''[Collapsed]''
- Download ''[Expanded]''
--- UpgradeGuide
--- DownloadGuide ''[Collapsed]''
- Tutorial
Forum ''[Collapsed]''

#4 @leflo
11 years ago

  • Keywords has-patch added; tag menu page removed

Done that. (I'm missing that part too).

#5 @leflo
11 years ago

  • Resolution set to duplicate
  • Status changed from reopened to closed

#6 @Nazgul
11 years ago

  • Milestone 2.1 deleted
Note: See TracTickets for help on using tickets.