Opened 16 years ago
Closed 16 years ago
#6345 closed enhancement (worksforme)
Function to return single post / page ID
Reported by: | Viper007Bond | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.5 |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
Proposal for a new function for use outside of The Loop:
If you're on a single post or page (i.e. is_single()
or is_page()
is TRUE
), this function would return the ID of that post or page, otherwise it'd return NULL
or whatever.
Now before you suggest it, global $post; echo $post-ID;
is unreliable because it can be thrown off by other Loops such as the "Recent Posts" sidebar widget.
Change History (3)
Note: See
TracTickets for help on using
tickets.
Why not this?
if (is_single()) $id = get_query_var('p');
else if (is_page()) $id = get_query_var('page_id');