WordPress.org

Make WordPress Core

Opened 10 years ago

Closed 9 years ago

Last modified 8 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:

Description

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

Proposed usage
is_current('42')

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

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

Purpose
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 9 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 @davidhouse10 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.

comment:2 @FireMotion10 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:
Wordpress

  • About

--- Who

  • Download

--- UpgradeGuide
--- DownloadGuide


  • Tutorial

Forum

  • Support
  • Development

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

  • 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."

comment:3 @FireMotion10 years ago

Menu's in previous post should read:

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

And:

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

@leflo9 years ago

comment:4 @leflo9 years ago

  • Keywords has-patch added; tag menu page removed

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

comment:5 @leflo9 years ago

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

comment:6 @Nazgul8 years ago

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