コード例 #1
0
ファイル: wp-postviews-plus.php プロジェクト: xxf1995/alphaV
function wp_pvp_template_replace($template, $post, $chars, $thumbnail_width, $thumbnail_height, $with_bot)
{
    $post_views = intval($post->views);
    $post_title = isset($post->post_title) ? $post->post_title : '';
    if ($chars > 0) {
        $post_title = pp_snippet_text($post_title, $chars);
    }
    if (current_theme_supports('post-thumbnails')) {
        if (post_type_supports($post->post_type, 'thumbnail')) {
            $thumbnail = get_the_post_thumbnail($post->ID, 'post-thumbnail');
            if ($thumbnail_width > 0) {
                $thumbnail = preg_replace('@ width="[0-9]*" @i', ' ', $thumbnail);
                $thumbnail = '<img width="' . $thumbnail_width . substr($thumbnail, 0, -4);
            }
            if ($thumbnail_height > 0) {
                $thumbnail = preg_replace('@ height="[0-9]*" @i', ' ', $thumbnail);
                $thumbnail = '<img $thumbnail_height="' . $thumbnail_height . substr($thumbnail, 0, -4);
            }
        }
    } else {
        $thumbnail = '';
    }
    $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
    $temp = stripslashes($template);
    $temp = wp_pvp_count_replace($temp, $with_bot ? 'both' : 'user', $post->ID, $post_views);
    $temp = str_replace("%POST_TITLE%", $post_title, $temp);
    $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp);
    $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp);
    $temp = str_replace("%POST_DATE%", mysql2date(get_option('date_format'), $post->post_date), $temp);
    $temp = str_replace("%POST_URL%", get_permalink($post->ID), $temp);
    $temp = str_replace("%POST_THUMBNAIL%", $thumbnail, $temp);
    return $temp;
}
コード例 #2
0
ファイル: wp-postviews.php プロジェクト: NickTaporuk/cd
 function get_least_viewed_tag($tag_id = 0, $mode = '', $limit = 10, $chars = 0, $display = true)
 {
     global $wpdb;
     $views_options = get_option('views_options');
     $where = '';
     $temp = '';
     $output = '';
     if (is_array($tag_id)) {
         $tag_sql = "{$wpdb->term_taxonomy}.term_id IN (" . join(',', $tag_id) . ')';
     } else {
         $tag_sql = "{$wpdb->term_taxonomy}.term_id = {$tag_id}";
     }
     if (!empty($mode) && $mode != 'both') {
         if (is_array($mode)) {
             $mode = implode("','", $mode);
             $where = "post_type IN ('" . $mode . "')";
         } else {
             $where = "post_type = '{$mode}'";
         }
     } else {
         $where = '1=1';
     }
     $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 INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id) INNER JOIN {$wpdb->term_taxonomy} ON ({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id) WHERE post_date < '" . current_time('mysql') . "' AND {$wpdb->term_taxonomy}.taxonomy = 'post_tag' AND {$tag_sql} AND {$where} AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER BY views ASC LIMIT {$limit}");
     if ($most_viewed) {
         foreach ($most_viewed as $post) {
             $post_views = intval($post->views);
             $post_title = get_the_title($post);
             if ($chars > 0) {
                 $post_title = snippet_text($post_title, $chars);
             }
             $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
             $temp = stripslashes($views_options['most_viewed_template']);
             $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp);
             $temp = str_replace("%POST_TITLE%", $post_title, $temp);
             $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp);
             $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp);
             $temp = str_replace("%POST_URL%", get_permalink($post), $temp);
             $temp = str_replace("%POST_DATE%", get_the_time(get_option('date_format'), $post), $temp);
             $temp = str_replace("%POST_TIME%", get_the_time(get_option('time_format'), $post), $temp);
             $output .= $temp;
         }
     } else {
         $output = '<li>' . __('N/A', 'wp-postviews') . '</li>' . "\n";
     }
     if ($display) {
         echo $output;
     } else {
         return $output;
     }
 }
コード例 #3
0
 /**
  * 获取浏览次数最多的文章列表
  * 目前没有用
  */
 public function get_most_viewed($mode = '', $limit = 10, $chars = 0, $display = true)
 {
     global $wpdb;
     $views_options = get_option('views_options');
     $where = '';
     $temp = '';
     $output = '';
     if (!empty($mode) && $mode != 'both') {
         if (is_array($mode)) {
             $mode = implode("','", $mode);
             $where = "post_type IN ('" . $mode . "')";
         } else {
             $where = "post_type = '{$mode}'";
         }
     } else {
         $where = '1=1';
     }
     $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}");
     if ($most_viewed) {
         foreach ($most_viewed as $post) {
             $post_views = intval($post->views);
             $post_title = get_the_title($post);
             if ($chars > 0) {
                 $post_title = snippet_text($post_title, $chars);
             }
             $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
         }
     } else {
     }
 }