function _get_most_viewed($mode = '', $limit = 10, $chars = 0, $display = true) { global $wpdb, $post; $where = ''; $temp = ''; 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 {$where} AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER BY views DESC LIMIT {$limit}"); if ($most_viewed) { if ($chars > 0) { foreach ($most_viewed as $post) { $post_title = get_the_title(); $post_views = intval($post->views); $post_views = number_format($post_views); $temp .= "<a href=\"" . _get_permalink($post->ID) . "\">" . snippet_chars($post_title, $chars) . "</a> - {$post_views} " . __('views', 'wp-postviews') . "<br/>"; } } else { foreach ($most_viewed as $post) { $post_title = get_the_title(); $post_views = intval($post->views); $post_views = number_format($post_views); $temp .= "<a href=\"" . _get_permalink($post->ID) . "\">{$post_title}</a><br/>"; } } } else { $temp = __('No Posts', 'wap') . '<br/>'; } if ($display) { echo $temp; } else { return $temp; } }
function get_mostemailed($mode = '', $limit = 10, $chars = 0, $echo = true) { global $wpdb, $post; $where = ''; $temp = ''; if (!empty($mode) && $mode != 'both') { $where = "post_type = '{$mode}'"; } else { $where = '1=1'; } $mostemailed = $wpdb->get_results("SELECT {$wpdb->posts}.*, COUNT({$wpdb->email}.email_postid) AS email_total FROM {$wpdb->email} LEFT JOIN {$wpdb->posts} ON {$wpdb->email}.email_postid = {$wpdb->posts}.ID WHERE post_date < '" . current_time('mysql') . "' AND {$where} AND post_password = '' AND post_status = 'publish' GROUP BY {$wpdb->email}.email_postid ORDER BY email_total DESC LIMIT {$limit}"); if ($mostemailed) { if ($chars > 0) { foreach ($mostemailed as $post) { $post_title = get_the_title(); $email_total = intval($post->email_total); $temp .= "<li><a href=\"" . get_permalink() . "\">" . snippet_chars($post_title, $chars) . "</a> - {$email_total} " . __('emails', 'wp-email') . "</li>\n"; } } else { foreach ($mostemailed as $post) { $post_title = get_the_title(); $email_total = intval($post->email_total); $temp .= "<li><a href=\"" . get_permalink() . "\">{$post_title}</a> - {$email_total} " . __('emails', 'wp-email') . "</li>\n"; } } } else { $temp = '<li>' . __('N/A', 'wp-email') . '</li>' . "\n"; } if ($echo) { echo $temp; } else { return $temp; } }