#2364 closed enhancement (duplicate)
Create is_page_or_child() Template Tag
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | low | Milestone: | |
| Component: | Template | Version: | 1.2 |
| Severity: | normal | Keywords: | has-patch |
| 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)
Change History (7)
comment:1
davidhouse — 7 years ago
- Resolution set to invalid
- Status changed from new to closed
comment:2
FireMotion — 7 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
FireMotion — 7 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]''
- Keywords has-patch added; tag,menu,page removed
Done that. (I'm missing that part too).
- Resolution set to duplicate
- Status changed from reopened to closed

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