<?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>wordpress post views count without plugin - TsupamaN.com</title>
	<atom:link href="https://www.tsupaman.com/tag/wordpress-post-views-count-without-plugin/feed" rel="self" type="application/rss+xml" />
	<link>https://www.tsupaman.com/tag/wordpress-post-views-count-without-plugin</link>
	<description>ทำเว็บไซต์ด้วย Wordpress</description>
	<lastBuildDate>Sat, 26 Apr 2014 18:46:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
	<item>
		<title>WordPress : นับจำนวนคนอ่านบทความ แบบไม่ใช้ Plugin</title>
		<link>https://www.tsupaman.com/2014/04/wordpress-%e0%b8%99%e0%b8%b1%e0%b8%9a%e0%b8%88%e0%b8%b3%e0%b8%99%e0%b8%a7%e0%b8%99%e0%b8%84%e0%b8%99%e0%b8%ad%e0%b9%88%e0%b8%b2%e0%b8%99-%e0%b9%84%e0%b8%a1%e0%b9%88%e0%b9%83%e0%b8%8a%e0%b9%89-plugin</link>
		
		<dc:creator><![CDATA[TsupamaN]]></dc:creator>
		<pubDate>Sat, 26 Apr 2014 18:46:23 +0000</pubDate>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[post views plugin wordpress]]></category>
		<category><![CDATA[wordpress post view count]]></category>
		<category><![CDATA[wordpress post views]]></category>
		<category><![CDATA[wordpress post views count without plugin]]></category>
		<category><![CDATA[wordpress นับคนอ่าน]]></category>
		<category><![CDATA[wordpress นับจำนวนคนอ่าน]]></category>
		<guid isPermaLink="false">https://www.tsupaman.com/?p=873</guid>

					<description><![CDATA[<p>ที่แล้วๆ มา ผมใช้ WordPress ในการทำเว็บอะไรก็แล้วแต่ เน้นไปที่ความสะดวกสบายไว้ก่อน เช่น การใช้งาน Plugin เพิ่มความสะดวกสบายให้กับตัวเอง แต่พอนานๆ เข้า เริ่มไม่คิดแบบนั้นแล้ว เพราะว่า ยิ่งเรามี Plugin ในระบบมากเท่าไร เว็บเราก็จะช้า และกินทรัพยากรของโฮสมากเท่านั้น และยังเป็นสาเหตุของการถูกแฮคอีกด้วย วันนี้ ผมเอาฟังก์ชั่น wordpress นับจำนวนคนอ่าน บทความแบบง่ายๆ มาให้เอาไปใช้กันครับ โดยที่คุณจะลืมไปเลยว่า Plugin ที่ชื่อ wp_pageview นั้น หน้าตาเป็นอย่างไร เปิดไฟล์ functions.php ขึ้นมา แล้วใส่โค้ดด้านล่างนี้ลงไปครับ function getPostViews($postID){ $count_key = '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, '1'); return '1 View'; [&#8230;]</p>
<p>The post <a href="https://www.tsupaman.com/2014/04/wordpress-%e0%b8%99%e0%b8%b1%e0%b8%9a%e0%b8%88%e0%b8%b3%e0%b8%99%e0%b8%a7%e0%b8%99%e0%b8%84%e0%b8%99%e0%b8%ad%e0%b9%88%e0%b8%b2%e0%b8%99-%e0%b9%84%e0%b8%a1%e0%b9%88%e0%b9%83%e0%b8%8a%e0%b9%89-plugin">WordPress : นับจำนวนคนอ่านบทความ แบบไม่ใช้ Plugin</a> appeared first on <a href="https://www.tsupaman.com">TsupamaN.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>ที่แล้วๆ มา ผมใช้ <strong>WordPress</strong> ในการทำเว็บอะไรก็แล้วแต่ เน้นไปที่ความสะดวกสบายไว้ก่อน เช่น การใช้งาน Plugin เพิ่มความสะดวกสบายให้กับตัวเอง แต่พอนานๆ เข้า เริ่มไม่คิดแบบนั้นแล้ว เพราะว่า ยิ่งเรามี Plugin ในระบบมากเท่าไร เว็บเราก็จะช้า และกินทรัพยากรของโฮสมากเท่านั้น และยังเป็นสาเหตุของการถูกแฮคอีกด้วย</p>
<p><a href="https://www.tsupaman.com/wp-content/uploads/2013/08/wordpress.png" data-rel="lightbox-gallery-ivP5hUzX" data-rl_title="" data-rl_caption="" title=""><img decoding="async" class="aligncenter size-full wp-image-292" alt="wordpress" src="https://www.tsupaman.com/wp-content/uploads/2013/08/wordpress.png" width="200" height="200" srcset="https://www.tsupaman.com/wp-content/uploads/2013/08/wordpress.png 200w, https://www.tsupaman.com/wp-content/uploads/2013/08/wordpress-100x100.png 100w" sizes="(max-width: 200px) 100vw, 200px" /></a></p>
<p>วันนี้ ผมเอาฟังก์ชั่น <strong>wordpress นับจำนวนคนอ่าน</strong> บทความแบบง่ายๆ มาให้เอาไปใช้กันครับ โดยที่คุณจะลืมไปเลยว่า <strong>Plugin </strong>ที่ชื่อ<strong> wp_pageview</strong> นั้น หน้าตาเป็นอย่างไร</p>
<p><strong>เปิดไฟล์ functions.php ขึ้นมา แล้วใส่โค้ดด้านล่างนี้ลงไปครับ</strong></p>
<pre class="lang:php decode:true" title="Post Views Functions">function getPostViews($postID){
    $count_key = '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, '1');
        return '1 View';
    }
    return $count.' Views';
}

// function to count views.
function setPostViews($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 1;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '1');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}

// Add it to a column in WP-Admin - (Optional)
add_filter('manage_posts_columns', 'posts_column_views');
add_action('manage_posts_custom_column', 'posts_custom_column_views',5,2);
function posts_column_views($defaults){
    $defaults['post_views'] = __('Views');
    return $defaults;
}
function posts_custom_column_views($column_name, $id){
    if($column_name === 'post_views'){
        echo getPostViews(get_the_ID());
    }
}</pre>
<p><strong> จากโค้ดด้านบน จะอธิบายคร่าวๆดังนี้นะครับ</strong></p>
<ul>
<li><strong>ฟังก์ชั่น setPostViews()</strong> จะทำการ<strong> &#8220;นับ&#8221;</strong> หากเราเปิดหน้าบทความนั้นๆขึ้นมา</li>
<li><strong>ฟังก์ชั่น getPostViews()</strong> จะทำการ <strong>&#8220;แสดง&#8221;</strong> ค่าที่นับเข้ามา</li>
</ul>
<p>งงมั๊ยเอ่ย ถ้างง มาดูกันต่อ</p>
<h3>การใช้งานฟังก์ชั่นทั้งสอง <strong>setPostViews()</strong> และ <strong>getPostViews()</strong></h3>
<p>ผมยกตัวอย่างในไฟล์ single.php ละกัน</p>
<pre class="lang:php decode:true">&lt;?php if (have_posts()) : ?&gt; 
&lt;?php setPostViews(get_the_ID()); ?&gt;
&lt;div class="grid_8_bg"&gt;
	&lt;?php while (have_posts()) : the_post(); ?&gt; 
	&lt;div class="content"&gt;
		&lt;div class="page-breadcrumbs"&gt;&lt;?php if(function_exists('bcn_display')){ bcn_display(); }?&gt;&lt;/div&gt;
		&lt;div class="page-title"&gt;&lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt;&lt;/div&gt;
		&lt;div class="page-detail"&gt;
                     &lt;?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?&gt; &lt;/b&gt; (&lt;?php echo getPostViews(get_the_ID()); ?&gt;)
                &lt;/div&gt;
		&lt;div class="page-content"&gt;
			&lt;?php the_content(''); ?&gt;	
		&lt;/div&gt;
		&lt;div class="page-content-tag"&gt;
			&lt;span&gt;Tags (คำค้นหา)&lt;/span&gt;
			&lt;span class="img-tag"&gt;&lt;img src="&lt;?php bloginfo('template_url'); ?&gt;/images/tags.png"/&gt;&lt;/span&gt;&lt;p&gt;&lt;?php the_tags( '', ', ', ''); ?&gt;&lt;/p&gt;
		&lt;/div&gt;
		&lt;div class="clear"&gt;&lt;/div&gt;

	&lt;/div&gt;
	&lt;?php endwhile; ?&gt;
&lt;/div&gt;
&lt;?php else : ?&gt;
&lt;div&gt;
     &lt;div style="width:640px;text-align:center;padding:50px 10px;font-size:24px;"&gt;ขออภัย! ยังไม่มีเนื้อหาสำหรับหมวดนี้....&lt;/div&gt;
&lt;/div&gt;
&lt;?php  endif; ?&gt;</pre>
<p>ลองดูตัวอย่างแล้วงงอีก คอมเม้นต์ถามกันมาได้นะครับ สำหรับการใช้ฟังก์ชั่นทั้งสองนี้ แล้วคุณจะไม่ต้องนึกถึง plugin wp_pageview อีกเลย ลองเอาไปใช้กันดูสำหรับ <strong>WordPress : นับจำนวนคนอ่านบทความ แบบไม่ใช้ Plugin</strong></p>
<p><strong>บทความโดย : tsupaman</strong></p>
<p>The post <a href="https://www.tsupaman.com/2014/04/wordpress-%e0%b8%99%e0%b8%b1%e0%b8%9a%e0%b8%88%e0%b8%b3%e0%b8%99%e0%b8%a7%e0%b8%99%e0%b8%84%e0%b8%99%e0%b8%ad%e0%b9%88%e0%b8%b2%e0%b8%99-%e0%b9%84%e0%b8%a1%e0%b9%88%e0%b9%83%e0%b8%8a%e0%b9%89-plugin">WordPress : นับจำนวนคนอ่านบทความ แบบไม่ใช้ Plugin</a> appeared first on <a href="https://www.tsupaman.com">TsupamaN.com</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
