duanqiongchong0354 2019-05-11 16:59
浏览 66
已采纳

如何修复在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

    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.

  • 写回答

1条回答 默认 最新

  • douanrang4728 2019-05-13 06:00
    关注

    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.

    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> ";
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?