本文整理汇总了PHP中dwqa_vote_count函数的典型用法代码示例。如果您正苦于以下问题:PHP dwqa_vote_count函数的具体用法?PHP dwqa_vote_count怎么用?PHP dwqa_vote_count使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dwqa_vote_count函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dwqa_action_vote
function dwqa_action_vote()
{
$result = array('error_code' => 'authorization', 'error_message' => __('Are you cheating, huh?', 'dwqa'));
$vote_for = isset($_POST['vote_for']) && sanitize_text_field($_POST['vote_for']) == 'question' ? 'question' : 'answer';
if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field($_POST['nonce']), '_dwqa_' . $vote_for . '_vote_nonce')) {
wp_send_json_error($result);
}
if (!isset($_POST[$vote_for . '_id'])) {
$result['error_code'] = 'missing ' . $vote_for;
$result['error_message'] = __('What ' . $vote_for . ' are you looking for?', 'dwqa');
wp_send_json_error($result);
}
$post_id = sanitize_text_field($_POST[$vote_for . '_id']);
$point = isset($_POST['type']) && sanitize_text_field($_POST['type']) == 'up' ? 1 : -1;
//vote
if (is_user_logged_in()) {
global $current_user;
if (!dwqa_is_user_voted($post_id, $point)) {
$votes = maybe_unserialize(get_post_meta($post_id, '_dwqa_votes_log', true));
$votes[$current_user->ID] = $point;
//update
do_action('dwqa_vote_' . $vote_for, $post_id, (int) $point);
update_post_meta($post_id, '_dwqa_votes_log', serialize($votes));
// Update vote point
dwqa_update_vote_count($post_id);
$point = dwqa_vote_count($post_id);
if ($point > 0) {
$point = '+' . $point;
}
wp_send_json_success(array('vote' => $point));
} else {
$result['error_code'] = 'voted';
$result['error_message'] = __('You voted for this ' . $vote_for, 'dwqa');
wp_send_json_error($result);
}
} elseif ('question' == $vote_for) {
// useful of question with meta field is "_dwqa_question_useful", point of this question
$useful = get_post_meta($post_id, '_dwqa_' . $vote_for . '_useful', true);
$useful = $useful ? (int) $useful : 0;
do_action('dwqa_vote_' . $vote_for, $post_id, (int) $point);
update_post_meta($post_id, '_dwqa_' . $vote_for . '_useful', $useful + $point);
// Number of votes by guest
$useful_rate = get_post_meta($post_id, '_dwqa_' . $vote_for . '_useful_rate', true);
$useful_rate = $useful_rate ? (int) $useful_rate : 0;
update_post_meta($post_id, '_dwqa_' . $vote_for . '_useful_rate', $useful_rate + 1);
}
}
示例2: dwqa_get_the_best_answer
function dwqa_get_the_best_answer($question_id = false)
{
if (!$question_id) {
$question_id = get_the_ID();
}
if ('dwqa-question' != get_post_type($question_id)) {
return false;
}
global $dwqa, $wpdb;
$user_vote = get_post_meta($question_id, '_dwqa_best_answer', true);
if ($user_vote && get_post($user_vote)) {
return $user_vote;
}
$answer_id = get_transient('dwqa-best-answer-for-' . $question_id);
if (!$answer_id) {
$answers = get_posts(array('post_type' => $dwqa->answer->get_slug(), 'posts_per_page' => 1, 'meta_key' => '_dwqa_votes', 'meta_query' => array('relation' => 'AND', array('key' => '_question', 'value' => $question_id . '', 'compare' => '=')), 'fields' => 'ids', 'orderby' => 'meta_value_num', 'order' => 'DESC'));
$answer_id = !empty($answers) ? $answers[0] : false;
set_transient('dwqa-best-answer-for-' . $question_id, $answer_id, 21600);
}
if ($answer_id && (int) dwqa_vote_count($answer_id) > 2) {
return $answer_id;
}
return false;
}
示例3: dwqa_question_columns_content
function dwqa_question_columns_content($column_name, $post_ID)
{
switch ($column_name) {
case 'info':
echo ucfirst(get_post_meta($post_ID, '_dwqa_status', true)) . '<br>';
echo '<strong>' . dwqa_question_answers_count($post_ID) . '</strong> ' . __('answered', 'dwqa') . '<br>';
echo '<strong>' . dwqa_vote_count($post_ID) . '</strong> ' . __('voted', 'dwqa') . '<br>';
echo '<strong>' . dwqa_question_views_count($post_ID) . '</strong> ' . __('views', 'dwqa') . '<br>';
break;
case 'question-category':
$terms = wp_get_post_terms($post_ID, 'dwqa-question_category');
$i = 0;
foreach ($terms as $term) {
if ($i > 0) {
echo ', ';
}
echo '<a href="' . get_term_link($term, 'dwqa-question_category') . '">' . $term->name . '</a> ';
$i++;
}
break;
case 'question-tag':
$terms = wp_get_post_terms($post_ID, 'dwqa-question_tag');
$i = 0;
foreach ($terms as $term) {
if ($i > 0) {
echo ', ';
}
echo '<a href="' . get_term_link($term, 'dwqa-question_tag') . '">' . $term->name . '</a> ';
$i++;
}
break;
}
}
示例4: dwqa_question_meta_button
function dwqa_question_meta_button($post_id = false)
{
if (!$post_id) {
$post_id = get_the_ID();
}
?>
<div class="dwqa-meta">
<div class="dwqa-vote" data-type="question" data-nonce="<?php
echo wp_create_nonce('_dwqa_question_vote_nonce');
?>
" data-question="<?php
echo $post_id;
?>
" >
<a class="dwqa-vote-dwqa-btn dwqa-vote-up" data-vote="up" href="#" title="<?php
_e('Vote Up', 'dwqa');
?>
"><?php
_e('Vote Up', 'dwqa');
?>
</a>
<div class="dwqa-vote-count"><?php
$point = dwqa_vote_count();
echo $point > 0 ? '+' . $point : $point;
?>
</div>
<a class="dwqa-vote-dwqa-btn dwqa-vote-down" data-vote="down" href="#" title="<?php
_e('Vote Down', 'dwqa');
?>
"><?php
_e('Vote Down', 'dwqa');
?>
</a>
</div>
<?php
dwqa_question_status_button($post_id);
?>
<?php
dwqa_question_privacy_button($post_id);
?>
<?php
$categories = wp_get_post_terms($post_id, 'dwqa-question_category');
?>
<?php
if (!empty($categories)) {
?>
<?php
$cat = $categories[0];
?>
<div class="dwqa-category">
<a class="dwqa-category-name" href="<?php
echo get_term_link($cat);
?>
" title="<?php
_e('All questions from', 'dwqa');
?>
<?php
echo $cat->name;
?>
"><i class="fa fa-folder-open"></i> <?php
echo $cat->name;
?>
</a>
</div>
<?php
}
?>
<!-- Question Categories -->
<?php
dwqa_question_action_buttons($post_id);
?>
<?php
if (is_user_logged_in()) {
?>
<span data-post="<?php
echo $post_id;
?>
" data-nonce="<?php
echo wp_create_nonce('_dwqa_follow_question');
?>
" class="dwqa-favourite <?php
echo dwqa_is_followed($post_id) ? 'active' : '';
?>
" title="<?php
echo dwqa_is_followed($post_id) ? __('Unfollow This Question', 'dwqa') : __('Follow This Question', 'dwqa');
?>
"><!-- add class 'active' -->
<span class="dwpa_follow"><?php
_e('follow', 'dwqa');
?>
</span>
<span class="dwpa_following"><?php
_e('following', 'dwqa');
?>
</span>
//.........这里部分代码省略.........
示例5: get_the_term_list
echo get_the_term_list(get_the_ID(), 'dwqa-question_category', '<span class="dwqa-question-category">' . __(' • ', 'dwqa'), ', ', '</span>');
?>
</div>
<div class="dwqa-question-stats">
<span class="dwqa-views-count">
<?php
$views_count = dwqa_question_views_count();
?>
<?php
printf(__('<strong>%1$s</strong> views', 'dwqa'), $views_count);
?>
</span>
<span class="dwqa-answers-count">
<?php
$answers_count = dwqa_question_answers_count();
?>
<?php
printf(__('<strong>%1$s</strong> answers', 'dwqa'), $answers_count);
?>
</span>
<span class="dwqa-votes-count">
<?php
$vote_count = dwqa_vote_count();
?>
<?php
printf(__('<strong>%1$s</strong> votes', 'dwqa'), $vote_count);
?>
</span>
</div>
</div>
示例6: wp_create_nonce
<span class="dwqa-vote" data-type="question" data-nonce="<?php
echo wp_create_nonce('_dwqa_question_vote_nonce');
?>
" data-question="<?php
echo $post_id;
?>
" >
<a class="dwqa-vote-dwqa-btn dwqa-vote-up" data-vote="up" href="#" title="<?php
_e('Vote Up', 'dwqa');
?>
"><?php
_e('Vote Up', 'dwqa');
?>
</a>
<div class="dwqa-vote-count"><?php
$point = dwqa_vote_count();
echo $point > 0 ? '+' . $point : $point;
?>
</div>
<a class="dwqa-vote-dwqa-btn dwqa-vote-down" data-vote="down" href="#" title="<?php
_e('Vote Down', 'dwqa');
?>
"><?php
_e('Vote Down', 'dwqa');
?>
</a>
</span>
<?php
if (is_user_logged_in()) {
?>
示例7: dwqa_get_the_best_answer
function dwqa_get_the_best_answer($question_id = false)
{
if (!$question_id) {
$question_id = get_the_ID();
}
if ('dwqa-question' != get_post_type($question_id)) {
return false;
}
$user_vote = get_post_meta($question_id, '_dwqa_best_answer', true);
if ($user_vote && get_post($user_vote)) {
return $user_vote;
}
global $wpdb;
$query = "SELECT `post_id` FROM `{$wpdb->prefix}postmeta` LEFT JOIN `{$wpdb->prefix}posts` \n ON `{$wpdb->prefix}postmeta`.post_id = `{$wpdb->prefix}posts`.ID \n WHERE `post_id` \n IN ( SELECT `post_id` FROM `{$wpdb->prefix}postmeta` \n WHERE `meta_key` = '_question' AND `meta_value` = {$question_id} ) \n AND `meta_key` = '_dwqa_votes'\n ORDER BY CAST( `meta_value` as DECIMAL ) DESC LIMIT 0,1";
$answer_id = $wpdb->get_var($query);
if ($answer_id && (int) dwqa_vote_count($answer_id) > 2) {
return $answer_id;
}
return false;
}
示例8: dwqa_question_answers_count
</div>
<div class="dwqa-comment">
<?php
$answer_count = dwqa_question_answers_count();
?>
<?php
if ($answer_count > 0) {
printf('<strong>%d</strong> %s', $answer_count, _n('answer', 'answers', $answer_count, 'dwqa'));
?>
<?php
} else {
echo '<strong>0</strong> ' . __('answer', 'dwqa');
}
?>
</div>
<div class="dwqa-vote">
<?php
$answer_vote = dwqa_vote_count();
?>
<?php
if ($answer_vote > 0) {
printf('<strong>%d</strong> %s', $answer_vote, _n('vote', 'votes', $answer_vote, 'dwqa'));
?>
<?php
} else {
echo '<strong>0</strong> ' . __('vote', 'dwqa');
}
?>
</div>
</footer>
</article>
示例9: do_action
*/
?>
<?php
do_action('dwqa_before_single_question_content');
?>
<div class="dwqa-question-item">
<div class="dwqa-question-vote" data-nonce="<?php
echo wp_create_nonce('_dwqa_question_vote_nonce');
?>
" data-post="<?php
the_ID();
?>
">
<span class="dwqa-vote-count"><?php
echo dwqa_vote_count();
?>
</span>
<a class="dwqa-vote dwqa-vote-up" href="#"><?php
_e('Vote Up', 'dwqa');
?>
</a>
<a class="dwqa-vote dwqa-vote-down" href="#"><?php
_e('Vote Down', 'dwqa');
?>
</a>
</div>
<div class="dwqa-question-meta">
<?php
$user_id = get_post_field('post_author', get_the_ID()) ? get_post_field('post_author', get_the_ID()) : false;
?>
示例10: dwqa_get_the_best_answer
function dwqa_get_the_best_answer($question_id = false)
{
if (!$question_id) {
$question_id = get_the_ID();
}
if ('dwqa-question' != get_post_type($question_id)) {
return false;
}
$user_vote = get_post_meta($question_id, '_dwqa_best_answer', true);
if ($user_vote && get_post($user_vote)) {
return $user_vote;
}
$answer_id = wp_cache_get('dwqa-best-answer-for-' . $question_id, 'dwqa');
if (!$answer_id) {
global $wpdb;
$query = "SELECT `post_id` FROM `{$wpdb->postmeta}`\n\t\t\t\t\tWHERE `post_id` IN ( \n\t\t\t\t\t\t\tSELECT `post_id` FROM `{$wpdb->postmeta}` \n\t\t\t\t\t\t\tWHERE `meta_key` = '_question' AND `meta_value` = {$question_id} \n\t\t\t\t\t) \n\t\t\t\t\tAND `meta_key` = '_dwqa_votes'\n\t\t\t\t\tORDER BY CAST( `meta_value` as DECIMAL ) DESC LIMIT 0,1";
$answer_id = $wpdb->get_var($query);
if (!$answer_id) {
$answer_id = -1;
}
wp_cache_set('dwqa-best-answer-for-' . $question_id, $answer_id, 'dwqa', 21600);
}
if ($answer_id && (int) dwqa_vote_count($answer_id) > 2) {
return $answer_id;
}
return false;
}
示例11: single_question
public function single_question()
{
global $post, $current_user;
$post_id = get_the_ID();
?>
<div class="dwqa-single-question">
<!-- dwqa-status-private -->
<article id="question-<?php
echo $post_id;
?>
" <?php
post_class('dwqa-question');
?>
>
<header class="dwqa-header">
<h1 class="dwqa-title"><?php
the_title();
?>
</h1>
<div class="dwqa-meta">
<span class="dwqa-vote" data-type="question" data-nonce="<?php
echo wp_create_nonce('_dwqa_question_vote_nonce');
?>
" data-question="<?php
echo $post_id;
?>
" >
<a class="dwqa-vote-dwqa-btn dwqa-vote-up" data-vote="up" href="#" title="<?php
_e('Vote Up', 'dwqa');
?>
"><?php
_e('Vote Up', 'dwqa');
?>
</a>
<div class="dwqa-vote-count"><?php
$point = dwqa_vote_count();
echo $point > 0 ? '+' . $point : $point;
?>
</div>
<a class="dwqa-vote-dwqa-btn dwqa-vote-down" data-vote="down" href="#" title="<?php
_e('Vote Down', 'dwqa');
?>
"><?php
_e('Vote Down', 'dwqa');
?>
</a>
</span>
<?php
if (is_user_logged_in()) {
?>
<span data-post="<?php
echo $post_id;
?>
" data-nonce="<?php
echo wp_create_nonce('_dwqa_follow_question');
?>
" class="dwqa-favourite <?php
echo dwqa_is_followed($post_id) ? 'active' : '';
?>
" title="<?php
echo dwqa_is_followed($post_id) ? __('Unfollow This Question', 'dwqa') : __('Follow This Question', 'dwqa');
?>
"><!-- add class 'active' -->
<i class="fa fa-star"></i>
</span>
<?php
}
?>
</div>
</header>
<div class="dwqa-content">
<?php
the_content();
?>
</div>
<?php
$tags = get_the_term_list($post_id, 'dwqa-question_tag', '<span class="dwqa-tag">', '</span><span class="dwqa-tag">', '</span>');
if (!empty($tags)) {
?>
<div class="dwqa-tags"><?php
echo $tags;
?>
</div>
<?php
}
?>
<!-- Question Tags -->
<footer class="dwqa-footer">
<div class="dwqa-author">
<?php
echo get_avatar($post->post_author, 32, false);
?>
<span class="author">
<?php
printf('<a href="%1$s" title="%2$s %3$s">%3$s</a>', get_author_posts_url(get_the_author_meta('ID')), __('Posts by', 'dwqa'), get_the_author_meta('display_name'));
?>
</span><!-- Author Info -->
<span class="dwqa-date">
//.........这里部分代码省略.........