dongyange1101 2017-05-04 04:13
浏览 14

如何将“Time Ago”放在Wordpress文本区域?

I’d like to add a text line saying that “The latest event has been ended 3 days ago”

And the part “3 days ago” will automatically change as the day goes by, e.g. 1 month ago and so on…. Is there any shortcode plugin I can use for this? Or any method?

I found this plugin https://wordpress.org/plugins/the-time-ago/ but it seems to work with post/page/comment time. Not for a text line.

Best.

  • 写回答

2条回答 默认 最新

  • 啊啊啊小孔 2017-05-04 05:49
    关注

    If you want to use a custom timestamp for the event and know how to write basic php code, you can use the php's DateTime::diff method or better, use Carbon to get the difference between your custom timestamp and today's date.

    Examples in the linked docs should suffice in understanding and to echo the difference between the dates. Now, use that inside WordPress, write that code in a function in your theme's functions.php file and return the value to create a shortcode for the difference.

    function eventdiff_func( $atts ) {
    
        // write code which calculates the difference here and store it in $diff
    
        return $diff;
    }
    add_shortcode( 'event_diff', 'eventdiff_func' );
    

    Now you can use the [event_diff] shortcode whereever you'd like to output the difference that you calculated.

    评论

报告相同问题?

悬赏问题

  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因