Exemple #1
0
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;
}
Exemple #2
0
function is_question_answered($question_id = 0, $type = 'any')
{
    if (!$question_id) {
        $question_id = get_the_ID();
    }
    if ('accepted' == $type) {
        return get_post_meta($question_id, 'accepted_answer', true);
    } else {
        return get_answer_count($question_id) > 0;
    }
}
/** Luo HTML vastausten lukum\"{a}\"{a}r\"{a}lle
 * @param $question_id integer
 */
function create_question_count_box($question_id)
{
    /* 
     * $number_of_answers array
     */
    $number_of_answers = get_answer_count($question_id);
    echo "<div class='question_summary'>";
    echo "<a class='username_box' id='no_underline' href='?question_id=" . $question_id . "'>";
    if ($number_of_answers[$question_id]['count'] == 1) {
        echo "<div id='answered'>" . "<div id='answer_count'>" . $number_of_answers[$question_id]['count'] . "</div>" . "<div> answer</div>" . "</div>";
    } else {
        if ($number_of_answers[$question_id]['count'] > 1) {
            echo "<div id='answered'>" . "<div id='answer_count'>" . $number_of_answers[$question_id]['count'] . "</div>" . "<div> answers</div>" . "</div>";
        }
    }
    if ($number_of_answers[$question_id]['count'] == 0) {
        echo "<div id='unanswered'>" . "<div id='answer_count'>" . $number_of_answers[$question_id]['count'] . "</div>" . "<div> answers</div>" . "</div>";
    }
    echo "</a>";
}
function get_the_answer_count($question_id = 0)
{
    $count = get_answer_count($question_id ? $question_id : get_the_ID());
    return sprintf(_n('1 Answer', '%d Answers', $count, QA_TEXTDOMAIN), number_format_i18n($count));
}