如何在wordpress文章中修复显示日期显示为空

我正在模板标记中编辑代码以显示WordPress网站上的最后修改日期, 我的意思是, 如果我更新帖子, 则它应有条件地显示更新, 并忽略”已发布”, 如果我不这样做, 则应保留原样。

我可以使用它, 我遇到的问题是” Published On”出现在我的所有帖子上:http://prntscr.com/nn9hfl, 到目前为止, 这是我的代码

    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>'
        );

我希望仅在帖子更新的情况下, 结果才会显示”更新日期”

我可以发现问题出在$ posted_on = sprintf(之间, 并且可以看到实际日期中包含永久链接, 如果发布更新, 我如何更正代码以在更新日期中包含永久链接, 以及如果未更新。

谢谢。


#1


我已经重新格式化了你的代码, 以便有条件地显示发布日期和更新日期。另外, 我为发布日期和更新日期添加了正确的链接。请检查以下内容。

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> ";
    }
}

来源:

https://www.srcmini02.com/63314.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37648.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?