Problem: I would like to calculate the age of a post, in number of days, based on its publish date, and display that number for each post in a View of posts.
Solution: It would require a custom shortcode to calculate the difference between today's date and the post's publish date and display that in a View, something like this:
add_shortcode( 'num-days', 'wpv_num_days_shortcode'); function wpv_num_days_shortcode( $atts ) { $atts = shortcode_atts( array( 'postid' => '' ), $atts ); $timestamp = get_the_date( 'U', $atts['postid'] ); if( $timestamp != '') { $age = floor((time() - $timestamp) / ( 60*60*24 )) ; return $age; }else { return 0; } }
Then in the front-end the shortcode is like this:
[num-days postid="[wpv-post-id]"]
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
Dieses Thema enthält 22 Antworten, hat 3 Stimmen.
Zuletzt aktualisiert von vor 4 Jahren, 12 Monaten.
Assistiert von: Christian Cox.