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.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
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)
Este tema contiene 22 respuestas, tiene 3 mensajes.
Última actualización por hace 4 años, 10 meses.
Asistido por: Christian Cox.