💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
【阅读次数纯代码】 functions.php加入: ~~~ //postviews function get_post_views ($post_id) { $count_key = 'views'; $count = get_post_meta($post_id, $count_key, true); if ($count == '') { delete_post_meta($post_id, $count_key); add_post_meta($post_id, $count_key, '0'); $count = '0'; } echo number_format_i18n($count); } function set_post_views () { global $post; $post_id = $post -> ID; $count_key = 'views'; $count = get_post_meta($post_id, $count_key, true); if (is_single() || is_page()) { if ($count == '') { delete_post_meta($post_id, $count_key); add_post_meta($post_id, $count_key, '0'); } else { update_post_meta($post_id, $count_key, $count + 1); } } } add_action('get_header', 'set_post_views'); ~~~ single.php任意地方,或者循环代码中调用: `<?php get_post_views($post -> ID); ?> views` 参考: http://zmingcx.com/no-plugin-wordpress-reads.html 【插件WP-PostViews】 参考: https://www.wpdaxue.com/wp-postviews.html https://wordpress.org/plugins/wp-postviews/ 【对比】 阅读次数统计,纯代码对比插件,更有优势,测试同一后台,同一阅读次数代码,更换主题,可以继承之前主题的阅读统计次数