رفتن به مطلب

نمایش تعداد بازدید پست های وردپرس در پیشخوان


miraziz

پست های پیشنهاد شده

در در ۱۳۹۷/۱۰/۲۵ در 20:05، mehran-b گفته است :

اینو تست کنید.


<?php

//آمار بازدید پست ها				
	
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 . ' بازدید';
     
    //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 . ' بازدید';
        }
        //In all other cases return (count) Views
        else {
        return $count . ' بازدیدها';
        }
    }
}		
			
		
		
//Function: 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: Add/Register the Non-sortable 'Views' Column to your Posts tab in WP Dashboard.
function post_column_views($newcolumn){
    //Retrieves the translated string, if translation exists, and assign it to the 'default' array.
	if(current_user_can('administrator')) {
		
		$newcolumn['post_views'] = __('بازدیدها');
		
		return $newcolumn;
		
	} else {
		
		return $newcolumn;
		
	}
	
}
//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' );
 
//Function: Populate the 'Views' Column with the views count in the WP dashboard.
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 action. 
//allows you to add custom columns to the list post/custom post type pages.
//'10' default: specify the function's priority.
//'2' is the number of the functions' arguments.
add_action('manage_posts_custom_column', 'post_custom_column_views',10,2);
 
/**UP TO HERE IS THE SAME AS CODE-3. NEXT IS WHAT IS REQUIRED FOR SORTABLE 'VIEWS' COLUMN**/
 
//Function: Register the 'Views' column as sortable in the WP dashboard.
function register_post_column_views_sortable( $newcolumn ) {
	
	if(current_user_can('administrator')) {
		
		$newcolumn['post_views'] = __('بازدیدها');
		
		return $newcolumn;
		
	} else {
		
		return $newcolumn;
		
	}
	
}
add_filter( 'manage_edit-post_sortable_columns', 'register_post_column_views_sortable' );
 
//Function: Sort Post Views in WP dashboard based on the Number of Views (ASC or DESC).
function sort_views_column( $vars ) 
{
    if ( isset( $vars['orderby'] ) && 'post_views' == $vars['orderby'] ) {
        $vars = array_merge( $vars, array(
            'meta_key' => 'post_views_count', //Custom field key
            'orderby' => 'meta_value_num') //Custom field value (number)
        );
    }
    return $vars;
}
add_filter( 'request', 'sort_views_column' );		
?>

 

سلام آقا مهران. من اخیرا افزونه موشک وردپرس را نصب کردم. وقتی این افزونه را فعال می کنم متاسفانه آمار دیگه هاصلا بروز نمیشه. یعنی آمار تمامی ÷ست ها درآخرین عددی که قبل از نصب افزونه باقی مانده بود را نشون میده و هر چه قدر صفحه را رفرش کنم, باز تغییری در آمار رخ نمیده. این مشکل را میشه بدون غیرفعال کردن افزونه حل کرد؟

لینک به ارسال
در 8 ساعت قبل، miraziz گفته است :

سلام آقا مهران. من اخیرا افزونه موشک وردپرس را نصب کردم. وقتی این افزونه را فعال می کنم متاسفانه آمار دیگه هاصلا بروز نمیشه. یعنی آمار تمامی ÷ست ها درآخرین عددی که قبل از نصب افزونه باقی مانده بود را نشون میده و هر چه قدر صفحه را رفرش کنم, باز تغییری در آمار رخ نمیده. این مشکل را میشه بدون غیرفعال کردن افزونه حل کرد؟

با وجود کش دیگه نمیشه کاریش کرد و آمار اشتباه میشه.

لینک به ارسال
  • 4 ماه بعد...
در در ۱۳۹۹/۴/۲۸ در 19:27، mehran-b گفته است :

با وجود کش دیگه نمیشه کاریش کرد و آمار اشتباه میشه.

سلام آقا مهران. وقت بخیر. این قالب را من برای یکی از دوستان خریداری کردم. همانطور که می بینید با وجود افزونه‌ی کش باز تعداد بازدید ها را نشون میده. میشه شرح کوچکی از روش کار این شمارشگر بدید و اینکه آیا امکان استخراج کدهای شمارشگر از فایل قالب وجود دارد؟
http://qalmag.ir/2018/12/10/everyones-a-combo-of-a-2018-movie-and-tv/

لینک به ارسال
در 12 ساعت قبل، miraziz گفته است :

سلام آقا مهران. وقت بخیر. این قالب را من برای یکی از دوستان خریداری کردم. همانطور که می بینید با وجود افزونه‌ی کش باز تعداد بازدید ها را نشون میده. میشه شرح کوچکی از روش کار این شمارشگر بدید و اینکه آیا امکان استخراج کدهای شمارشگر از فایل قالب وجود دارد؟
http://qalmag.ir/2018/12/10/everyones-a-combo-of-a-2018-movie-and-tv/

از AJAX استفاده کرده برای نمایش و شمارش بازدید.

لینک به ارسال

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع ...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...