Opened 4 years ago
Last modified 4 years ago
#52761 new enhancement
Date Permalinks
Reported by: | dshanske | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Date/Time | Keywords: | |
Focuses: | Cc: |
Description
This one surprised me that there is no functionality around it I could find in the code.
A function to generate a date permalink. Specifically, in use case, let's say, in my post, I want to display the date.. March 10, 2021, and link it to the day archive. Then, on the day archive, I want a prev and next button for the day before and day after for better navigation.
There is no simple functionality for this that I see. I can write functions to do this, but it seems to me there should be built in functions to figure out what date archive the current retrieved URL is, to generate the permalinks to a day, month, or year archive based on a WP_Post object/post ID or a DateTime object.
Change History (3)
#2
@
4 years ago
I think I was unclear, apologies. There is no function for getting a permalink directly from the current archive page...You would have to determine what query was being made then feed it into the functions you identified. Also no function to get it from a DateTime or post object..
For example...
get_post_date_permalink( $post, type = 'day' )
get_datetime_permalink( $datetime, $type )
#3
@
4 years ago
There isn't an established API pattern in core of generating an archive link from a specific post object.
To be clear, is there something you can't achieve with existing functions? Or not having ready-made function to do exactly this is the only issue?
If latter, it doesn't sound too useful to me personally. Though there are plenty of very niche functions in core. :)
is_date()
,is_day()
, and several more, see a date page in conditional tags. Global$wp_query
would have query variables of which specific date is it.get_day_link()
,get_month_link()
,get_year_link()
Day before/after isn't trivial because there might be no posts in them.
get_adjacent_post()
can be used to figure that out, but it gets clunky.Would that be enough for your needs?
Or please suggest how would you envision a specific function that covers something that is currently missing.