当前位置: 首页 > 技术文档, 资源共享 > 正文
avatar

编辑wp-postviews.php,在插件目录下哦,找到下面的这段类似的代码: 这是4.41版本的,大概都差 […]

QQ图片20160109121709
编辑wp-postviews.php,在插件目录下哦,找到下面的这段类似的代码:

if ($should_count ) {
            wp_enqueue_script('wp-postviews-cache', plugins_url('postviews-cache.js', __FILE__), array('jquery'), '1.64', true);
            wp_localize_script('wp-postviews-cache', 'viewsCacheL10n', array('admin_ajax_url' => admin_url('admin-ajax.php', (is_ssl() ? 'https' : 'http')), 'post_id' => intval($post->ID)));
        }

这是4.41版本的,大概都差不多!
把”if ($should_count ) {“和最这个反中括号去掉”}”!
去掉后的代码因该是这样的:

 wp_enqueue_script('wp-postviews-cache', plugins_url('postviews-cache.js', __FILE__), array('jquery'), '1.64', true);
            wp_localize_script('wp-postviews-cache', 'viewsCacheL10n', array('admin_ajax_url' => admin_url('admin-ajax.php', (is_ssl() ? 'https' : 'http')), 'post_id' => intval($post->ID)));

把下面的代码添加到wp-postviews.php中:

add_action('wp_ajax_nopriv_show_postview', 'show_postview');
add_action('wp_ajax_show_postview', 'show_postview');
function show_postview(){
    $views_options = get_option('views_options');
    $ID = $_POST["bigfa_view"];
    $custom_fields = get_post_custom($ID);
    $my_custom_field = $custom_fields['views'];
    foreach ( $my_custom_field as $key => $value ) {
        echo str_replace('%VIEW_COUNT%', number_format_i18n($value), $views_options['template']);
    }
    die;
}

打开插件目录下的,postviews-cache.js
在最下面添加如下代码:

jQuery(document).ready(function() {
    var ajax_data = {
        action: "show_postview",
        bigfa_view: viewsCacheL10n.post_id
    };
    $.post(viewsCacheL10n.admin_ajax_url, ajax_data,
    function(data) {
        $('.show-view').html(data);
    });
    return false;
});
本文固定链接: https://blog.yanhualou.com/jishu/638.html | 烟花楼博客
标签:,

真正解决wp-super-cache wp-postviews不计数问题:等您坐沙发呢!

发表评论

快捷键:Ctrl+Enter