WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 8 months ago

#23202 new defect (bug)

Enable is_page_template() within the Loop

Reported by: wpsmith Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: has-patch reporter-feedback
Focuses: template Cc:

Description

There have been a few times where, in the loop, I need to know if I were on a page using a specific page template.

The function in_the_loop() provides this functionality for us to expand is_page_template().

Attachments (2)

23202.patch (779 bytes) - added by wpsmith 2 years ago.
23202.alt.patch (1.1 KB) - added by wpsmith 20 months ago.
Alternative solution

Download all attachments as: .zip

Change History (7)

@wpsmith2 years ago

comment:1 @alexvorn22 years ago

  • Component changed from General to Template

comment:2 @wpsmith2 years ago

  • Keywords has-patch dev-feedback added

@wpsmith20 months ago

Alternative solution

comment:3 @nacin16 months ago

  • Component changed from Template to Posts, Post Types
  • Focuses template added

comment:4 @nacin13 months ago

Unless I'm reading this wrong, it seems like the issue here is the usage of query_posts(). query_posts() does change the active $wp_query and thus all conditionals.

This should work fine if you're on a page with a page template inside a loop. But *the* loop doesn't really make any sense as that should be the actual page (singular).

Alternatively, if it's proposing that it should work inside the loop for the current page: I think this would break things by changing the return value. While can take a function and make it work outside of the loop, taking a function and changing its behavior inside the loop is gonna cause problems.

Maybe I just don't understand the problem.

comment:5 @obenland8 months ago

  • Keywords reporter-feedback added; dev-feedback removed

Travis, would you mind elaborating the use case?

Note: See TracTickets for help on using tickets.