function hui_recent_posts_most() { global $wpdb; // $days=400; $days = _hui('most_list_date'); $limit = _hui('most_list_number'); $output = ''; if (!_hui('most_list_style') || _hui('most_list_style') == 'comment') { $today = date("Y-m-d H:i:s"); $daysago = date("Y-m-d H:i:s", strtotime($today) - $days * 24 * 60 * 60); $result = $wpdb->get_results("SELECT comment_count, ID, post_title, post_date FROM {$wpdb->posts} WHERE post_date BETWEEN '{$daysago}' AND '{$today}' AND post_status='publish' AND post_type='post' ORDER BY comment_count DESC LIMIT 0 , {$limit}"); if (empty($result)) { $output = '<li>' . __('暂无文章!', 'haoui') . __('近期有评论的文章才会显示在这里,你也可以在主题设置中选择按阅读数排行。', 'haoui') . '</li>'; } else { $i = 1; foreach ($result as $topten) { $postid = $topten->ID; $title = $topten->post_title; $commentcount = $topten->comment_count; if ($commentcount != 0) { $output .= '<li><p class="text-muted"><span class="post-comments">' . __('评论', 'haoui') . ' (' . $commentcount . ')</span>' . hui_get_post_like($class = 'post-like', $pid = $postid) . '</p><span class="label label-' . $i . '">' . $i . '</span><a' . hui_target_blank() . ' href="' . get_permalink($postid) . '" title="' . $title . '">' . $title . '</a></li>'; $i++; } } } } else { if (_hui('most_list_style') == 'view') { global $post; $limit_date = current_time('timestamp') - $days * 86400; $limit_date = date("Y-m-d H:i:s", $limit_date); $where = ''; $mode = 'post'; if (!empty($mode) && $mode != 'both') { $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 post_date > '" . $limit_date . "' AND {$where} AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER BY views DESC LIMIT {$limit}"); if ($most_viewed) { $i = 1; foreach ($most_viewed as $post) { $title = get_the_title(); $post_views = intval($post->views); // $output .= '<li class="item-'.$i.'"><a target="_blank" href="'.get_permalink($postid).'">'._get_post_thumbnail(array()).'<h2>'.$post_title.'</h2><p>'.hui_get_post_date( get_the_time('Y-m-d H:i:s') ).'<span class="post-views">阅读('.$post_views.')</span></p></a></li>'; $output .= '<li><p class="text-muted"><span class="post-comments">' . __('阅读', 'haoui') . ' (' . $post_views . ')</span>' . hui_get_post_like($class = 'post-like', $pid = $postid) . '</p><span class="label label-' . $i . '">' . $i . '</span><a' . hui_target_blank() . ' href="' . get_permalink($postid) . '" title="' . $title . '">' . $title . '</a></li>'; $i++; } } else { $output = '<li>' . __('暂无文章!', 'haoui') . '</li>'; } } } echo '<div class="most-comment-posts"> <h3 class="title"><strong>' . _hui('most_list_title') . '</strong></h3> <ul>' . $output . '</ul> </div>'; }
function hui_posts_focus() { $html = ''; $html .= '<li class="large"><a' . hui_target_blank() . ' href="' . _hui('focus_href') . '"><img class="thumb" data-original="' . _hui('focus_src') . '"><h4>' . _hui('focus_title') . '</h4></a></li>'; $sticky = get_option('sticky_posts'); rsort($sticky); query_posts(array('post__in' => $sticky, 'ignore_sticky_posts' => 1, 'showposts' => 4)); if (have_posts()) { while (have_posts()) { the_post(); $html .= '<li><a' . hui_target_blank() . ' href="' . get_permalink() . '">'; $html .= hui_get_thumbnail(); $html .= '<h4>' . get_the_title() . '</h4>'; $html .= '</a></li>'; } } wp_reset_query(); echo '<div class="focusmo"><ul>' . $html . '</ul></div>'; }
function widget($args, $instance) { extract($args); $title = apply_filters('widget_name', $instance['title']); $limit = $instance['limit']; $cat = $instance['cat']; $orderby = $instance['orderby']; $showstyle = $instance['showstyle']; // $img = $instance['img']; $style = ' class="' . $showstyle . '"'; echo $before_widget; echo $before_title . $title . $after_title; echo '<ul' . $style . '>'; $args = array('order' => DESC, 'cat' => $cat, 'orderby' => $orderby, 'showposts' => $limit, 'ignore_sticky_posts' => 1); query_posts($args); while (have_posts()) { the_post(); ?> <li><a<?php echo hui_target_blank(); ?> href="<?php the_permalink(); ?> "><?php if ($showstyle !== 'items-03') { echo '<span class="thumbnail">' . hui_get_thumbnail() . '</span>'; } ?> <span class="text"><?php the_title(); ?> </span><?php echo hui_get_views($class = 'text-muted post-views'); ?> </a></li> <?php } wp_reset_query(); echo '</ul>'; echo $after_widget; }
function hui_posts_sticky() { $title = _hui('sticky_title'); $showposts = _hui('sticky_limit'); $sticky = get_option('sticky_posts'); rsort($sticky); query_posts(array('post__in' => $sticky, 'ignore_sticky_posts' => 1, 'showposts' => $showposts)); if (have_posts()) { printf('<div class="sticky"><h3 class="title"><strong>' . $title . '</strong></h3><ul>'); while (have_posts()) { the_post(); echo '<li class="item"><a' . hui_target_blank() . ' href="' . get_permalink() . '">'; echo hui_get_thumbnail(); echo get_the_title(); echo '</a></li>'; } printf('</ul></div>'); } wp_reset_query(); }
function widget($args, $instance) { extract($args); $title = apply_filters('widget_name', $instance['title']); $limit = $instance['limit']; $outer = $instance['outer']; if (!$outer) { $outer = -1; } echo $before_widget; echo $before_title . $title . $after_title; echo '<ul>'; global $wpdb; $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved,comment_author_email, comment_type,comment_author_url, SUBSTRING(comment_content,1,60) AS com_excerpt FROM {$wpdb->comments} LEFT OUTER JOIN {$wpdb->posts} ON ({$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID) WHERE user_id!='" . $outer . "' AND comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT {$limit}"; $comments = $wpdb->get_results($sql); foreach ($comments as $comment) { $output .= $comment->user_id . '<li><a' . hui_target_blank() . ' href="' . get_permalink($comment->ID) . '#comment-' . $comment->comment_ID . '" title="' . $comment->post_title . __('上的评论', 'haoui') . '">' . hui_get_avatar($user_id = $comment->user_id, $user_email = $comment->comment_author_email) . strip_tags($comment->comment_author) . ' <span class="text-muted">' . timeago($comment->comment_date_gmt) . __('说:', 'haoui') . '<br>' . str_replace(' src=', ' data-original=', convert_smilies(strip_tags($comment->com_excerpt))) . '</span></a></li>'; } echo $output; echo '</ul>'; echo $after_widget; }
function hui_posts_related($title = '', $limit = 8) { global $post; $exclude_id = $post->ID; $posttags = get_the_tags(); $i = 0; echo '<div class="relates"><h3 class="title"><strong>' . $title . '</strong></h3><ul>'; if ($posttags) { $tags = ''; foreach ($posttags as $tag) { $tags .= $tag->name . ','; } $args = array('post_status' => 'publish', 'tag_slug__in' => explode(',', $tags), 'post__not_in' => explode(',', $exclude_id), 'caller_get_posts' => 1, 'orderby' => 'comment_date', 'posts_per_page' => $limit); query_posts($args); while (have_posts()) { the_post(); echo '<li><a' . hui_target_blank() . ' href="' . get_permalink() . '">' . hui_get_thumbnail() . get_the_title() . '</a></li>'; $exclude_id .= ',' . $post->ID; $i++; } wp_reset_query(); } if ($i < $limit) { $cats = ''; foreach (get_the_category() as $cat) { $cats .= $cat->cat_ID . ','; } $args = array('category__in' => explode(',', $cats), 'post__not_in' => explode(',', $exclude_id), 'caller_get_posts' => 1, 'orderby' => 'comment_date', 'posts_per_page' => $limit - $i); query_posts($args); while (have_posts()) { the_post(); echo '<li><a' . hui_target_blank() . ' href="' . get_permalink() . '">' . hui_get_thumbnail() . get_the_title() . '</a></li>'; $i++; } wp_reset_query(); } /*if ( $i == 0 ){ return false; }*/ echo '</ul></div>'; }
} } $focuscode = hui_get_thumbnail($imgSingle, false); $focuscode = $focuscode ? '<p class="focus"><a' . hui_target_blank() . ' href="' . get_permalink() . '" class="thumbnail">' . $focuscode . '</a></p>' : ''; } $author = get_the_author(); if (_hui('author_link')) { $author = '<a href="' . get_author_posts_url(get_the_author_meta('ID')) . '">' . $author . '</a>'; } $p_meta = _hui('post_plugin'); echo '<article class="excerpt' . $classname . '">'; echo '<header>'; if (!is_category()) { $category = get_the_category(); if ($category[0]) { echo '<a class="cat label label-important" href="' . get_category_link($category[0]->term_id) . '">' . $category[0]->cat_name . '<i class="label-arrow"></i></a> '; } } echo '<h2><a' . hui_target_blank() . ' href="' . get_permalink() . '" title="' . get_the_title() . _hui('connector') . get_bloginfo('name') . '">' . get_the_title() . '</a></h2>'; if ($img_number) { echo '<small class="text-muted"><span class="glyphicon glyphicon-picture"></span>' . $img_number . '</small>'; } echo '</header>', '<p class="text-muted time">' . ($p_meta && $p_meta['siteauthor'] ? get_bloginfo('name') . ' - ' : '') . $author . ' ' . __('发布于', 'haoui') . ' ' . hui_get_post_date(get_gmt_from_date(get_the_time('Y-m-d G:i:s'))) . '</p>', $focuscode, '<p class="note">' . hui_get_excerpt_content() . '</p>', '<p class="text-muted views">'; if (_hui('post_link_excerpt_s')) { hui_post_link(); } echo hui_get_views(), $p_meta && $p_meta['comm'] ? '<span class="post-comments">' . hui_get_comment_number() . '</span>' : '', hui_get_post_like($class = 'post-like'), the_tags('<span class="post-tags">' . __('标签:', 'haoui'), ' / ', '</span>'), '</p>'; echo '</article>'; } hui_paging(); wp_reset_query();