如何使用wp_get_theme修改singlepost.php

我如何使用wp_get_theme修改singlepost.php

//To keep the count accurate, lets get rid of prefetching
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
function hs_set_post_views($postID) {
    $count_key = 'hs_post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}

function hs_get_post_views($postID){
    $count_key = 'hs_post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "0 View";
    }
    return $count.' Views';
}

// Then add the following code inside your single post loop:
hs_get_post_views(get_the_ID());
hs_set_post_views(get_the_ID()); 

?>

我准备制作一个插件, 并且想要如何编辑singlepost.php以添加以下代码:

  hs_set_post_views(get_the_ID());

#1


这可能有效, 但尚未验证, 只是这个想法:

add_action('loop_start', 'hs_set_post_views_loop');

function hs_set_post_views_loop($post_ID) {
   if( is_single() ) {
      hs_set_post_views($post_ID);
   }
}

来源:

https://www.srcmini02.com/63526.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_37609.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?