ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

  แสดงกระทู้
หน้า: [1] 2 3 ... 13
1  พัฒนาเว็บไซต์ / CMS & Free Script / Re: [ถาม]วิธีทำให้แต่ละบทความแสดงจำนวน View เมื่อ: 11 ธันวาคม 2016, 02:11:02
ตอนนี้ใช้ปลั๊กอิน WP-Post View อยู่ค่ะ แต่มันแสดงผล View แค่ในหน้าต่างควบคุมของทาง Admin เท่านั้น อยากทราบว่าทำยังไงถึงจะแสดง View ของแต่ละบทความได้คะ ?
ตัวอย่างอยากได้ประมาณนี้ค่ะ



ขอบคุณทุกความเห็นค่ะ
'''



เพิ่มโค๊ดด้านล่างนี้เข้าไปในไฟล์ function.php เป็น function สำหรับ อัพเดทจำนวน views และแสดงจำนวน views
<?php
/************************************CODE-1***************************************
* @Author: Boutros AbiChedid
* @Date:   January 16, 2012
* @Websites: http://bacsoftwareconsulting.com/ ; http://blueoliveonline.com/
* @Description: Displays the Number of times Posts are Viewed on Your Blog.
* Function: Sets, Tracks and Displays the Count of Post Views (Post View Counter)
* Code is browser and JavaScript independent.
* @Tested on: WordPress version 3.2.1
*********************************************************************************/
//Set the Post Custom Field in the WP dashboard as Name/Value pair
function bac_PostViews($post_ID) {
 
    //Set the name of the Posts Custom Field.
    $count_key = 'post_views_count';
     
    //Returns values of the custom field with the specified key from the specified post.
    $count = get_post_meta($post_ID, $count_key, true);
     
    //If the the Post Custom Field value is empty.
    if($count == ''){
        $count = 0; // set the counter to zero.
         
        //Delete all custom fields with the specified key from the specified post.
        delete_post_meta($post_ID, $count_key);
         
        //Add a custom (meta) field (Name/value)to the specified post.
        add_post_meta($post_ID, $count_key, '0');
        return $count . ' View';
     
    //If the the Post Custom Field value is NOT empty.
    }else{
        $count++; //increment the counter by 1.
        //Update the value of an existing meta key (custom field) for the specified post.
        update_post_meta($post_ID, $count_key, $count);
         
        //If statement, is just to have the singular form 'View' for the value '1'
        if($count == '1'){
        return $count . ' View';
        }
        //In all other cases return (count) Views
        else {
        return $count . ' Views';
        }
    }
}
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
   
<?php
/************************************CODE-1***************************************
* @Author: Boutros AbiChedid
* @Date:   January 16, 2012
* @Websites: http://bacsoftwareconsulting.com/ ; http://blueoliveonline.com/
* @Description: Displays the Number of times Posts are Viewed on Your Blog.
* Function: Sets, Tracks and Displays the Count of Post Views (Post View Counter)
* Code is browser and JavaScript independent.
* @Tested on: WordPress version 3.2.1
*********************************************************************************/
//Set the Post Custom Field in the WP dashboard as Name/Value pair
function bac_PostViews($post_ID) {
 
    //Set the name of the Posts Custom Field.
    $count_key = 'post_views_count';
     
    //Returns values of the custom field with the specified key from the specified post.
    $count = get_post_meta($post_ID, $count_key, true);
     
    //If the the Post Custom Field value is empty.
    if($count == ''){
        $count = 0; // set the counter to zero.
         
        //Delete all custom fields with the specified key from the specified post.
        delete_post_meta($post_ID, $count_key);
         
        //Add a custom (meta) field (Name/value)to the specified post.
        add_post_meta($post_ID, $count_key, '0');
        return $count . ' View';
     
    //If the the Post Custom Field value is NOT empty.
    }else{
        $count++; //increment the counter by 1.
        //Update the value of an existing meta key (custom field) for the specified post.
        update_post_meta($post_ID, $count_key, $count);
         
        //If statement, is just to have the singular form 'View' for the value '1'
        if($count == '1'){
        return $count . ' View';
        }
        //In all other cases return (count) Views
        else {
        return $count . ' Views';
        }
    }
}
?>

จากนั้นให้นำโค๊ดด้านล่างนี้ไปใส่ใว้ในไฟล์ single.php (หน้าแสดงบทความ) เพื่อที่จะทำการอัพเดทจำนวน views และแสดงจำนวน views
<?php if(function_exists('bac_PostViews')) {
    echo bac_PostViews(get_the_ID());
}?>
1
2
3
   
<?php if(function_exists('bac_PostViews')) {
    echo bac_PostViews(get_the_ID());
}?>

สำหรับหน้ารวมบทความ (content.php หรือ index.php ) ให้ใช้โค๊ดด้านล่างนี้เพื่อแสดงจำนวน Views ของแต่ละบทความ (แสดงอย่างเดียว ไม่อัพเดทจำนวน Views)
<?php echo (int) get_post_meta(get_the_ID(), 'post_views_count', true) . ' View(s)'; ?>
1
   
<?php echo (int) get_post_meta(get_the_ID(), 'post_views_count', true) . ' View(s)'; ?>

หาต้องการแสดงคอร์ลัมน์ view ในส่วนของ Admin Dashboard ให้เพิ่มโค๊ดด้านล่างนี้เข้าไปในไฟล์ function.php

admincountview
<?php
/*********************************CODE-3********************************************
* @Author: Boutros AbiChedid
* @Date:   January 16, 2012
* @Websites: http://bacsoftwareconsulting.com/ ; http://blueoliveonline.com/
* @Description: Adds a Non-Sortable 'Views' Columnn to the Post Tab in WP dashboard.
* This code requires CODE-1(and CODE-2) as a prerequesite.
* Code is browser and JavaScript independent.
* @Tested on: WordPress version 3.2.1
***********************************************************************************/
 
//Gets the  number of Post Views to be used later.
function get_PostViews($post_ID){
    $count_key = 'post_views_count';
    //Returns values of the custom field with the specified key from the specified post.
    $count = get_post_meta($post_ID, $count_key, true);
 
    return $count;
}
 
//Function that Adds a 'Views' Column to your Posts tab in WordPress Dashboard.
function post_column_views($newcolumn){
    //Retrieves the translated string, if translation exists, and assign it to the 'default' array.
    $newcolumn['post_views'] = __('Views');
    return $newcolumn;
}
 
//Function that Populates the 'Views' Column with the number of views count.
function post_custom_column_views($column_name, $id){
     
    if($column_name === 'post_views'){
        // Display the Post View Count of the current post.
        // get_the_ID() - Returns the numeric ID of the current post.
        echo get_PostViews(get_the_ID());
    }
}
//Hooks a function to a specific filter action.
//applied to the list of columns to print on the manage posts screen.
add_filter('manage_posts_columns', 'post_column_views');
 
//Hooks a function to a specific action.
//allows you to add custom columns to the list post/custom post type pages.
//'10' default: specify the function's priority.
//and '2' is the number of the functions' arguments.
add_action('manage_posts_custom_column', 'post_custom_column_views',10,2);
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
   
<?php
/*********************************CODE-3********************************************
* @Author: Boutros AbiChedid
* @Date:   January 16, 2012
* @Websites: http://bacsoftwareconsulting.com/ ; http://blueoliveonline.com/
* @Description: Adds a Non-Sortable 'Views' Columnn to the Post Tab in WP dashboard.
* This code requires CODE-1(and CODE-2) as a prerequesite.
* Code is browser and JavaScript independent.
* @Tested on: WordPress version 3.2.1
***********************************************************************************/
 
//Gets the  number of Post Views to be used later.
function get_PostViews($post_ID){
    $count_key = 'post_views_count';
    //Returns values of the custom field with the specified key from the specified post.
    $count = get_post_meta($post_ID, $count_key, true);
 
    return $count;
}
 
//Function that Adds a 'Views' Column to your Posts tab in WordPress Dashboard.
function post_column_views($newcolumn){
    //Retrieves the translated string, if translation exists, and assign it to the 'default' array.
    $newcolumn['post_views'] = __('Views');
    return $newcolumn;
}
 
//Function that Populates the 'Views' Column with the number of views count.
function post_custom_column_views($column_name, $id){
     
    if($column_name === 'post_views'){
        // Display the Post View Count of the current post.
        // get_the_ID() - Returns the numeric ID of the current post.
        echo get_PostViews(get_the_ID());
    }
}
//Hooks a function to a specific filter action.
//applied to the list of columns to print on the manage posts screen.
add_filter('manage_posts_columns', 'post_column_views');
 
//Hooks a function to a specific action.
//allows you to add custom columns to the list post/custom post type pages.
//'10' default: specify the function's priority.
//and '2' is the number of the functions' arguments.
add_action('manage_posts_custom_column', 'post_custom_column_views',10,2);
?>

 

ดูเพิ่มเติม : http://bacsoftwareconsulting.c...in-wordpress-without-a-plugin/
2  อื่นๆ / ประกาศหาลูกจ้าง-อยากซื้อ / Re: รับซื้อ บัญชี adsens เก่า ไหม่ เมื่อ: 18 พฤศจิกายน 2016, 11:25:29
สนใจมั๊ยครับ ผมมีอยู่ 2 บัญชี แต่ขายแค่บัญชีเดียว พอดีบัญชีนี้ไม่ได้ใช้นานแล้ว อายุ 8 ปี รับเงินมาแล้ว เปลี่ยนที่อยู่ เปลี่ยนชื่อได้
ราคา pm มาครับ

pmไปแล้วครับ
3  อื่นๆ / ประกาศหาลูกจ้าง-อยากซื้อ / Re: รับซื้อ บัญชี adsens เก่า ไหม่ เมื่อ: 18 พฤศจิกายน 2016, 11:24:40
pmไปแล้วครับ
4  อื่นๆ / ประกาศหาลูกจ้าง-อยากซื้อ / Re: รับซื้อ บัญชี adsens เก่า ไหม่ เมื่อ: 17 พฤศจิกายน 2016, 23:06:35
ดันๆๆครับ
5  อื่นๆ / ประกาศหาลูกจ้าง-อยากซื้อ / รับซื้อ บัญชี adsens เก่า ไหม่ เมื่อ: 17 พฤศจิกายน 2016, 22:16:02
รับซื้อบัญชี Adsens เก่าไหม่
เปลี่ยนชื่อ ที่อยู่ได้
หรือรับ Pin ก็ดีครับ
เสนอราคามาได้เลยครับ
##############
ติดต่อ
ชุมโน เจริญกลาง
457 ถ.เสรีไทย แขวงคันนายาว
เขตคันนายาว กรุงเทพ 10230

tottipao99@hotmail.com
ศูนย์ แปด เก้า 063 สอง สี่ สาม แปด
6  อื่นๆ / ประกาศหาลูกจ้าง-อยากซื้อ / Re: รับเพิ่ม ไอดี adsense รับ PIN แล้ว 5000บาท เมื่อ: 12 มกราคม 2015, 09:55:44
ถ้ายังรับอยู่ pm หน่อยนะครับ  wanwan008


pm กลับแล้วครับ
ขออนุญาติท่าน  คนกำลังรวย
ถ้ามีหลายไอดี  ผมขอแบ่งซื้อด้วยคนครับ
7  อื่นๆ / ค้าๆขายๆ ( ห้ามใช้ Affiliate Link ) / Re: [รับสมัคร] Dropship ครีม/อาหารเสริม/เครื่องสำอางค์ กว่า 180รายการ+ ราคาส่ง เมื่อ: 29 ตุลาคม 2013, 15:05:46
PM ไปแล้วนะครับตอบกลับด้วย wanwan019
8  อื่นๆ / ค้าๆขายๆ ( ห้ามใช้ Affiliate Link ) / Re: รับจ้างสมัคร google adsense ผ่าน 100% ทีมงานมืออาชีพ เมื่อ: 05 ตุลาคม 2012, 16:56:37
โปรโมชั่น ลดสุดๆจาก 990 บาทเหลือ 350 บาทเท่านั้น รับ account ภายใน 2 วัน เร็วสุด 24 ชม. ถูกและเร็วที่สุดในไทย  wanwan019

โปรโมชั่นถึงวันไหนครับ ยืดไปยาวๆหน่อยก็ดีนะครับ เดี๋ยวผมได้มาอุดหนุนแน่

มายืนยันว่าใช้บริการท่านนี้ สมัคร2accout 2วันผ่านได้รับ เรียบร้อยพร้อมแปะcode โฆษณาแสดงเลยสุดยอดมากเลยครับ ตามหามานานได้เลยครับ wanwan020
9  อื่นๆ / ค้าๆขายๆ ( ห้ามใช้ Affiliate Link ) / Re: ขายสคริปเว็บวาไรตี้ เรียบหรู สวยงาม โปรโมชั่น 10 ท่านแรก ราคา 2000 บาท จำกัด 1 โดเมน เมื่อ: 14 กันยายน 2012, 13:21:26
มาอัพเดทการขายหน่อยครับ เพิ่งขายไปเมื่อกี้ สดๆ ร้อนๆ อีก 1 ท่านครับ
ณ ตอนนี้โปรโมชั่น ราคา 2000 บาท จำกัด 1 โดเมน เหลือเพียง 1 ท่านเท่านั้น สุดท้ายแล้วนะครับ
เร่ๆ เข้ามา รีบกันหน่อยนะครับ วันนี้มีผู้ขอทดสอบระบบ 3 ท่าน แต่ซื้อไปเพียง 1 ท่าน รออีก 2 ท่านให้คำตอบอยู่นะครับ
 wanwan017 wanwan017 wanwan017

โอนไปแล้วครับ2000
10  อื่นๆ / ค้าๆขายๆ ( ห้ามใช้ Affiliate Link ) / Re: ขายสคริปเว็บวาไรตี้ เรียบหรู สวยงาม โปรโมชั่น 10 ท่านแรก ราคา 2000 บาท จำกัด 1 โดเมน เมื่อ: 05 กันยายน 2012, 11:37:06
อัพเดทการขายตอนนี้ โปรโมชั่นเหลือ 3 ที่นะครับ
 wanwan044

ผมจองไว้1ที่ครับ 2000 บาท แบบ 5000ได้3สคริปยังมีอยู่ไหมครับ เผื่อเอาแบบ เต๊นรถและ job ด้วย
11  อื่นๆ / ค้าๆขายๆ ( ห้ามใช้ Affiliate Link ) / Re: $$ [[Variety Script]] ขาย สคริปต์วาไรตี้ ราคาคุณภาพ $$ by BuuScript.com เมื่อ: 10 สิงหาคม 2012, 14:24:28
ลืมถามว่ามีระบบสมาชิกไหมคาับหาไม่เจอในadmin

ของดีมีคุณภาพจัดไป1ละครับ มาช่วยดันครับ ของเขาดีจริงครับ
12  อื่นๆ / ค้าๆขายๆ ( ห้ามใช้ Affiliate Link ) / Re: $$ [[Variety Script]] ขาย สคริปต์วาไรตี้ ราคาคุณภาพ $$ by BuuScript.com เมื่อ: 10 สิงหาคม 2012, 14:22:39
ลืมถามว่ามีระบบสมาชิกไหมคาับหาไม่เจอในadmin
13  ความรู้ทั่วไป / E-commerce / Re: มีใครสนใจ รับตุ๊กตาพวกนี้ไปขาย ต่อบ้างคร้าบ เมื่อ: 26 กรกฎาคม 2012, 14:50:24
ขอรายละเอียดราคาปลีก+ราคาส่งด้วยค่ะ



เช่นกันครับ   สนใจๆๆๆๆๆๆ
14  อื่นๆ / ค้าๆขายๆ ( ห้ามใช้ Affiliate Link ) / Re: $$ [[Variety Script]] ขาย สคริปต์วาไรตี้ ราคาคุณภาพ $$ by BuuScript.com เมื่อ: 15 กรกฎาคม 2012, 13:24:28
เช็ค pm ด้วยนะครับ โอนเรียบร้อยแล้วครับผม อิอิ ชอบสวยๆ

ส่งให้ทางเมลแล้วนะครับ

###########################
อัพเดทครับ

Promotion พิเศษสำหรับสมาชิกไทยเสียว 5 ท่านแรก
    จำกัด 1 โดเมน ราคา 1,500 บาท    โอนแล้ว ส่งสคริปต์แล้ว 2 ท่าน  คงเหลือ 3 ท่านครับ
    ไม่จำกัดโดเมน ราคา 3,000 บาท    โอนแล้ว ส่งสคริปต์แล้ว 4 ท่าน  คงเหลือ 1 ท่านครับ

ขอบคุณลูกค้าทุกท่านครับ


จอง 1ที่ครับ รอเชื่อมบอร์ดด้วย


Promotion พิเศษสำหรับสมาชิกไทยเสียว 5 ท่านแรก เมื่อครบแล้ว ขายตามด้านบนนะครับ
   
    ไม่จำกัดโดเมน ราคา 3,000 บาท
15  อื่นๆ / Cafe / Re: ทำไงดีโรคจิต โทรมากวนทุกวันทกชั่วโมง (ผู้หญิงด้วย) เมื่อ: 03 พฤศจิกายน 2011, 22:14:32
ส่งมาให้ผมมาๆ   wanwan011

เบอร์ก็ตามนั้นละครับ ตอนนี้ยังมียิงมาหาผมเรื่อยๆๆพอผมโทรกลับก็ไม่รับ   รับแต่ไม่พูดครับ
16  อื่นๆ / Cafe / Re: ทำไงดีโรคจิต โทรมากวนทุกวันทกชั่วโมง (ผู้หญิงด้วย) เมื่อ: 03 พฤศจิกายน 2011, 22:06:59
ไม่ลองรับดูอ่ะครับ ถามว่าเป็นใคร


ลองรับแล้วครับเขาบอกเพื่อนยืมโทรศัพท์โทร
17  อื่นๆ / Cafe / Re: ทำไงดีโรคจิต โทรมากวนทุกวันทกชั่วโมง (ผู้หญิงด้วย) เมื่อ: 03 พฤศจิกายน 2011, 22:05:52


ทำไงดีโรคจิต โทรมากวนทุกวันทกชั่วโมง (ผู้หญิงด้วย

โทรมายิงมาได้ทุกวี่ทุกวันนะครับ ตอนนี้ก้ยังยิงมาอีก  สิบสายครับ   ยิงมาเรื่อยๆๆๆๆๆๆๆๆๆๆ   เบอร์นี้ครับ    080-3086025    มีไครเคยโดนบ้างครับ   รำคาญแล้ว




ยิงมาอีกแล้วครับ
18  อื่นๆ / Cafe / ทำไงดีโรคจิต โทรมากวนทุกวันทกชั่วโมง (ผู้หญิงด้วย) เมื่อ: 03 พฤศจิกายน 2011, 22:04:26


ทำไงดีโรคจิต โทรมากวนทุกวันทกชั่วโมง (ผู้หญิงด้วย

โทรมายิงมาได้ทุกวี่ทุกวันนะครับ ตอนนี้ก้ยังยิงมาอีก  สิบสายครับ   ยิงมาเรื่อยๆๆๆๆๆๆๆๆๆๆ   เบอร์นี้ครับ    080-3086025    มีไครเคยโดนบ้างครับ   รำคาญแล้ว
19  อื่นๆ / Cafe / Re: เกาหลีมาอีกแล้วครับ กำปั้นอดีตวง บาซูทำงานกับทีมงานเกาหลี ด่วนๆๆๆๆๆๆ สวดยวด เมื่อ: 05 พฤษภาคม 2011, 13:33:05
ทำไมต้องเลียนแบบเกาหลีหรอครับ  Huh?

คิดว่าคงว่าไมไ่ด้เลียบแบบนะครับคิดว่าอะไรที่ดีๆๆคงเอามาใช้นะครับ  เพราะพวกเราที่เห็นเกาหลีๆทำนะ ที่แท้เกาหลีก็เอาแนวคิดจากฝรั่งมาใช้เหมือนกันนะครับ

แบบว่าเอามาประยุกต์ใช้นะครับ  อันนี้ตามความคิดผมนะครับ wanwan023
20  อื่นๆ / Cafe / Re: เกาหลีมาอีกแล้วครับ ด่วนๆๆๆๆๆๆ สวดยวด เมื่อ: 05 พฤษภาคม 2011, 13:14:02
เข้ามา งง  wanwan004

มาแนะนำให้ลองฟังดูนะครับ
หน้า: [1] 2 3 ... 13