-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Post Date Style Customization #25456
Comments
This should probably be handled by themes using block-styles. It is possible... Replacing the function render_block_core_post_date( $attributes, $content, $block ) {
if ( ! isset( $block->context['postId'] ) ) {
return '';
}
$align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
$format = isset( $attributes['format'] ) ? $attributes['format'] : get_option( 'date_format' );
$format_arr = str_split( $format, 1 );
$final_date = '';
// Array extrapolated from https://www.php.net/manual/en/datetime.format.php
$valid_date_vals = array( 'd', 'D', 'j', 'l', 'N', 'S', 'w', 'z', 'W', 'F', 'm', 'M', 'n', 't', 'L', 'o', 'Y', 'y', 'a', 'A', 'B', 'g', 'G', 'h', 'H', 'i', 's', 'u', 'v', 'e', 'I', 'O', 'P', 'T', 'Z', 'c', 'r', 'U' );
foreach ( $format_arr as $part ) {
if ( ! in_array( $part, $valid_date_vals, true ) ) {
$final_date .= $part;
continue;
}
$final_date .= '<span class="date-val-' . $part . '">' . get_the_date( $part, $block->context['postId'] ) . '</span>';
}
return sprintf(
'<div class="%1$s"><time datetime="%2$s">%3$s</time></div>',
esc_attr( $align_class_name ),
get_the_date( 'c', $block->context['postId'] ),
$final_date
);
} |
This came up in feedback as part of the fifth call for testing for the FSE Outreach Program:
&
I wanted to include it here since it seems very related :) |
Here's another example of the sort of hyper-stylized query layout I'd like to see made possible (eventually) through post date format/style options: (Also relevant to #34192) |
#24957 is a similar issue, though it adds ideas for other Post Date block enhancements. This could be a bit free-wheeling, with great-power comes-great-responsibility-type of stuff, but I was playing around with a free-text formatter: Jan-21-2022.13-37-55.mp4With the right validation and better UX, e.g., proper labels for the shortcode characters maybe...? :) I like the idea of adding relative times, e.g., "Today or 3 days ago", as well mentioned in #24957 (comment) |
Awesome idea, @ramonjd! I might be getting ahead of myself, but I think if we can use something like that as the underlying data for it (and possibly allow a toggle for folks to edit it manually for advanced users) but then build an interactive WYSIWYG behaviour on top of it, it'd be pretty cool to have a reusable component that we could use anywhere where a date is presented? Maybe a +1 adding relative times would be very cool, too 😀 |
I believe this is completed in a general sense, but feel free to reopen if there's any specific that are missing. |
It feels less common to see this nowadays, but it could be nice to allow post date to be styled a little more interesting.
Examples:
The text was updated successfully, but these errors were encountered: