function get_badges($user) { // initiate badge array $badges = array(); // Get # of user posts, # of best answers $post_count = get_post_count($user); $answer_count = get_answer_count($user); // Assign post count badge if ($post_count >= 50) { $badges["posts"] = "<span title='50+ Posts' class='badge gold-poster " . $post_count . "'><!-- 50+ posts! --></span>"; } elseif ($post_count < 50 && $post_count >= 20) { $badges["posts"] = "<span title='20+ Posts' class='badge silver-poster " . $post_count . "'><!-- 20-49 posts --></span>"; } elseif ($post_count < 20 && $post_count >= 5) { $badges["posts"] = "<span title='5+ Posts' class='badge bronze-poster " . $post_count . "'><!-- 10-19 posts --></span>"; } else { $badges["posts"] = "<span class='badge " . $post_count . "'><!-- fewer than 5 posts --></span>"; } // Assign answer count badge if ($answer_count >= 25) { $badges["answers"] = "<span title='25 Best Answers' class='badge gold-answerer " . $answer_count . "'><!-- 25+ answers! --></span>"; } elseif ($answer_count < 25 && $answer_count >= 10) { $badges["answers"] = "<span title='10+ Best Answers' class='badge silver-answerer " . $answer_count . "'><!--10-24 answers --></span>"; } elseif ($answer_count < 10 && $answer_count >= 3) { $badges["answers"] = "<span title='3+ Best Answers' class='badge bronze-answerer " . $answer_count . "'><!-- 3-9 answers --></span>"; } else { $badges["answers"] = "<span class='badge " . $answer_count . "'><!-- fewer than 3 answers --></span>"; } // Return array of badges return $badges; }
$post_count = get_post_count($user_rows[$i]['user_id'], $where, $mode); // set it set_post_count($user_rows[$i]['user_id'], $post_count); } } else { // validate $username $username = !empty($HTTP_POST_VARS['username']) ? trim(strip_tags($HTTP_POST_VARS['username'])) : ''; // query for username $sql = "SELECT user_id\n\t\t\tFROM " . USERS_TABLE . "\n\t\t\t\tWHERE username = '******'"; $result = $db->sql_query($sql); if (!$result) { message_die(GENERAL_ERROR, "Could not get user Information", "", __LINE__, __FILE__, $sql); } $user_row = $db->sql_fetchrow($result); $num_rows = $db->sql_numrows($result); // if it doesn't exist, kill the script if ($num_rows == 0) { message_die(GENERAL_MESSAGE, $lang['No_such_user'] . $lang['Resync_redirect']); } // get the count $post_count = get_post_count($user_row['user_id'], $where, $mode); // set it set_post_count($user_row['user_id'], $post_count); } $redirect_message = sprintf($lang['Resync_redirect'], append_sid("admin_post_count_resync.php?mode=" . $HTTP_GET_VARS['mode']), append_sid("index.php?pane=right")); // completed message message_die(GENERAL_MESSAGE, $lang['Resync_completed'] . $redirect_message); } // Spit out the page. $template->pparse("body"); include 'page_footer_admin.' . $phpEx;
/** * @param $includedPostTypes * @param $category * @param $term_arr * @param $user_category_filter * * @return int */ function count_posts_by_filter($includedPostTypes, $category, $term_arr, $user_category_filter) { remove_all_filters('pre_get_posts'); remove_all_filters('posts_request'); remove_all_filters('the_posts'); $published_post_count = 0; foreach ($includedPostTypes as $incPostType) { $published_post_count += wp_count_posts($incPostType)->publish; } if ($category) { $published_post_count = get_post_count(array($category->term_id)); $published_post_count += ml_get_category_child_post_count($category->term_id, $term_arr['tax']); } if ($user_category_filter) { $arrayFilter = array(); $arrayFilterItems = explode(",", $user_category_filter); foreach ($arrayFilterItems as $afi) { $tcat = get_category_by_slug($afi); if (!$tcat) { $tcat = get_category($afi); } if ($tcat) { array_push($arrayFilter, $tcat->cat_ID); } } $published_post_count = get_post_count($arrayFilter); return $published_post_count; } return $published_post_count; }
/** * Is last post in the loop * @return bool * @todo add additional param to count page */ function is_last_post() { return get_post_count() == get_the_post_number() + 1; }