如何修复在wordpress帖子中显示为空的显示日期
问题描述:
I am editing code in template tags to show the last modified date on my WordPress website, what I mean is if I update the post, it should conditionally show update and ignore \"Published\", and if I do not, it should leave as is.
I got it to work, the problem I have is \"Published On\" appearing on all my post: http://prntscr.com/nn9hfl, this is my code so far
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
function chicken_wings_posted_on() { /** * Function to show last updated date */ $u_time = get_the_time(\'U\'); $u_modified_time = get_the_modified_time(\'U\'); if ($u_modified_time >= $u_time + 86400) { echo \'<p class = \"last-updated-up\">Last updated on \'; the_modified_time(\'F jS, Y\'); echo \"</p> \"; } else { echo \'<p class = \"entry-date published\">Published on \'; the_time(\'F jS, Y\'); echo \"</p> \"; } $time_string = sprintf( $time_string, esc_attr( get_the_date( \'c\' ) ), esc_html( get_the_date() ), esc_attr( get_the_modified_date( \'c\' ) ), esc_html( get_the_modified_date() ) ); $posted_on = sprintf( /* translators: %s: post date. */ esc_html_x( \'Published on %s\', \'post date\', \'chicken-wings\' ), \'<a href=\"\' . esc_url( get_permalink() ) . \'\" rel=\"bookmark\">\' . $time_string . \'</a>\' ); |
I expect the result to be showing Updated Date only if a post is updated only
I can spot the problem is between the $posted_on = sprintf(, and I can see that is including permalink on the actual date, how do I correct the code to include the permalink in the updated date if post updated, and the actual date if not updated.
Thanks.
网友观点:
I have reformatted your code to display the post date and updated date with conditional. Also I have added correct link for the published date and also updated date. Please check following.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
function chicken_wings_posted_on() { $u_time = get_the_time(\'U\'); $u_modified_time = get_the_modified_time(\'U\'); if ($u_modified_time >= $u_time + 86400) { echo \'<p class=\\\"last-updated-up\\\">Last updated on \'; echo \'<a href=\\\"\' . esc_url( get_day_link( get_the_modified_time( \'Y\' ), get_the_modified_time( \'m\' ), get_the_modified_time( \'d\' ) ) ) . \'\\\">\'; the_modified_time(\'F jS, Y\'); echo \'</a>\'; echo \\\"</p> \\\"; } else { echo \'<p class=\\\"entry-date published\\\">Published on \'; echo \'<a href=\\\"\' . esc_url( get_day_link( false, false, false ) ) . \'\\\">\'; the_time(\'F jS, Y\'); echo \'</a>\'; echo \\\"</p> \\\"; } } |
1. 带 [亲测] 说明源码已经被站长亲测过!
2. 下载后的源码请在24小时内删除,仅供学习用途!
3. 分享目的仅供大家学习和交流,请不要用于商业用途!
4. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
5. 本站所有资源来源于站长上传和网络,如有侵权请邮件联系站长!
6. 没带 [亲测] 代表站长时间紧促,站长会保持每天更新 [亲测] 源码 !
7. 盗版ripro用户购买ripro美化无担保,若设置不成功/不生效我们不支持退款!
8. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
9. 如果你也有好源码或者教程,可以到审核区发布,分享有金币奖励和额外收入!
10.如果您购买了某个产品,而我们还没来得及更新,请联系站长或留言催更,谢谢理解 !
GG资源网 » 如何修复在wordpress帖子中显示为空的显示日期