LOS MAS VISTOS,功能WORDPRESS

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LOS MAS VISTOS,功能WORDPRESS相关的知识,希望对你有一定的参考价值。

Funcion los post más vistos en wordpress.
  1. function get_most_viewed($mode = '', $limit = 10, $chars = 0, $display = true) {
  2. global $wpdb;
  3. $views_options = get_option('views_options');
  4. $where = '';
  5. $temp = '';
  6. $output = '';
  7. if(!empty($mode) && $mode != 'both') {
  8. $where = "post_type = '$mode'";
  9. } else {
  10. $where = '1=1';
  11. }
  12. $most_viewed = $wpdb->get_results("SELECT DISTINCT $wpdb->posts.*, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND $where AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER BY views DESC LIMIT $limit");
  13. if($most_viewed) {
  14. foreach ($most_viewed as $post) {
  15. $post_views = intval($post->views);
  16. $post_title = get_the_title($post);
  17. if($chars > 0) {
  18. $post_title = snippet_text($post_title, $chars);
  19. }
  20. $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
  21. $temp = stripslashes($views_options['most_viewed_template']);
  22. $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp);
  23. $temp = str_replace("%POST_TITLE%", $post_title, $temp);
  24. $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp);
  25. $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp);
  26. $temp = str_replace("%POST_URL%", get_permalink($post), $temp);
  27. $output .= $temp;
  28. }
  29. } else {
  30. $output = '<li>'.__('N/A', 'wp-postviews').'</li>'." ";
  31. }
  32. if($display) {
  33. echo $output;
  34. } else {
  35. return $output;
  36. }
  37. }

以上是关于LOS MAS VISTOS,功能WORDPRESS的主要内容,如果未能解决你的问题,请参考以下文章

php 儿童主题的Wordpres功能

php 查询帖子类型wordpres

php Wordpres检索密码电子邮件

PHP Wordpres,查询最新帖子

HTML 在wordpres强制换行

在wordpres中强制换行