Wie verbessert man die Anzahl der Post-Views?

Ich wollte wissen, ob ich die Art und Weise, wie ich Ansichten zähle, in WordPress ändern kann.

Beispiel: 1000 Ansichten = 1k – 10000 Ansichten = 10k

Ich zähle und betrachte Post-Views mit diesem Code:

// Count views function setPostViews($postID) { $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count=='') { $count = 0; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); } else { $count++; update_post_meta($postID, $count_key, $count); } } // Show views 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, '0'); return "0 View"; } return $count.' Views'; } // Show views in WP-Admin 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()); } } 

Solutions Collecting From Web of "Wie verbessert man die Anzahl der Post-Views?"

Ja, du kannst. Sie müssen überprüfen, ob die Anzahl der Post-Views höher als 1000 ist, also ist, dann runden Sie es und geben Sie es zurück:

 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, '0'); return "0 View"; } if ($count > 1000) { return round ( $count / 1000 ,1 ).'K Views'; } else { return $count.' Views'; } }