<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>我本善良 &#187; 阅读次数统计</title>
	<atom:link href="https://wbsl.org/tag/%e9%98%85%e8%af%bb%e6%ac%a1%e6%95%b0%e7%bb%9f%e8%ae%a1/feed" rel="self" type="application/rss+xml" />
	<link>https://wbsl.org</link>
	<description>一个不太正常的正常人</description>
	<lastBuildDate>Fri, 05 Jul 2024 01:35:05 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.2</generator>
	<item>
		<title>免插件实现WordPress文章阅读次数</title>
		<link>https://wbsl.org/web/122.html</link>
		<comments>https://wbsl.org/web/122.html#comments</comments>
		<pubDate>Thu, 25 Apr 2019 07:50:26 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[WEB前端]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[阅读次数统计]]></category>

		<guid isPermaLink="false">https://wbsl.org/?p=122</guid>
		<description><![CDATA[我这个主题默认没有阅读次数统计，所以就自己加了一个，方便也比较简单。我这个是没有插件的，个人觉得插件用的越少越<a href="https://wbsl.org/web/122.html" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p>我这个主题默认没有阅读次数统计，所以就自己加了一个，方便也比较简单。我这个是没有插件的，个人觉得插件用的越少越好，不得已的情况下再用插件比较好。</p>
<p>第一步、将下面代码加到主题functions模版文件中：</p><pre class="crayon-plain-tag">//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 -&gt; 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');</pre><p>第二步、将调用显示阅读次数代码加到single模版适当的位置：</p><pre class="crayon-plain-tag">&lt;?php get_post_views($post -&gt; ID); ?&gt; views</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>https://wbsl.org/web/122.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
