admin管理员组

文章数量:1026989

I have a poll, the vote of which must be closed for guests.

<ol class="zf-structure-list zf-quiz_answer zf-text zf-clearfix">
    <?php
    if( isset( $question["answers"] ) ) {
        foreach ($question["answers"] as $answer) {
            ?>
            <li class="zf-answer-item <?php if (isset($_COOKIE["zf_poll_vote_ans_" . $answer["answer_id"]])) echo 'zf-selected'; ?>"
                data-voted="<?php echo isset($poll_results["answers"][$answer["answer_id"]]) ? $poll_results["answers"][$answer["answer_id"]] : 0 ?>"
                data-id="<?php echo $answer["answer_id"]; ?>" data-post-id="<?php the_ID() ?>"
                data-group-id="<?php echo $question["question_id"]; ?>"
                data-voted-group="<?php echo isset($zombify_poll_results["groups"][$question["question_id"]]) ? $zombify_poll_results["groups"][$question["question_id"]] : 0 ?>">
               <div class="zf-answer js-zf-answer">
                   <div class="zf-checkbox-wrp"></div>
                   <div class="zf-poll-stat"></div>
                   <div class="zf-poll-stat_count"></div>
                   <div class="zf-answer_text">
                       <?php echo $answer["answer_text"]; ?>
                   </div>
               </div>
            </li>
        <?php
        }
    } ?>
</ol>

How to make that polls show for the guest, but when you click on the zf-answer-item, nothing happened?

Thanks!

I have a poll, the vote of which must be closed for guests.

<ol class="zf-structure-list zf-quiz_answer zf-text zf-clearfix">
    <?php
    if( isset( $question["answers"] ) ) {
        foreach ($question["answers"] as $answer) {
            ?>
            <li class="zf-answer-item <?php if (isset($_COOKIE["zf_poll_vote_ans_" . $answer["answer_id"]])) echo 'zf-selected'; ?>"
                data-voted="<?php echo isset($poll_results["answers"][$answer["answer_id"]]) ? $poll_results["answers"][$answer["answer_id"]] : 0 ?>"
                data-id="<?php echo $answer["answer_id"]; ?>" data-post-id="<?php the_ID() ?>"
                data-group-id="<?php echo $question["question_id"]; ?>"
                data-voted-group="<?php echo isset($zombify_poll_results["groups"][$question["question_id"]]) ? $zombify_poll_results["groups"][$question["question_id"]] : 0 ?>">
               <div class="zf-answer js-zf-answer">
                   <div class="zf-checkbox-wrp"></div>
                   <div class="zf-poll-stat"></div>
                   <div class="zf-poll-stat_count"></div>
                   <div class="zf-answer_text">
                       <?php echo $answer["answer_text"]; ?>
                   </div>
               </div>
            </li>
        <?php
        }
    } ?>
</ol>

How to make that polls show for the guest, but when you click on the zf-answer-item, nothing happened?

Thanks!

Share Improve this question edited Jan 2, 2019 at 17:55 Tom J Nowell 61.2k7 gold badges79 silver badges150 bronze badges asked Jan 2, 2019 at 16:59 Grosso2020Grosso2020 1 1
  • How are you implementing polls? I'm guessing based on the data attributes you're using a polls JS library, but you never mention which one, how it's added, how it runs, etc etc. Also where does this data come from? WP doesn't come with polls out of the box, are you using a custom plugin? Where does the $question array come from? How do you determine what a guest is? – Tom J Nowell Commented Jan 2, 2019 at 17:55
Add a comment  | 

1 Answer 1

Reset to default 0

You can check user logged in with is_user_logged_in. This is a simple function to check user logged in or not. Can you try this?

<ol class="zf-structure-list zf-quiz_answer zf-text zf-clearfix">
    <?php
  if(is_user_logged_in()){
    if( isset( $question["answers"] ) ) {
        foreach ($question["answers"] as $answer) {
            ?>
            <li class="zf-answer-item <?php if (isset($_COOKIE["zf_poll_vote_ans_" . $answer["answer_id"]])) echo 'zf-selected'; ?>"
                data-voted="<?php echo isset($poll_results["answers"][$answer["answer_id"]]) ? $poll_results["answers"][$answer["answer_id"]] : 0 ?>"
                data-id="<?php echo $answer["answer_id"]; ?>" data-post-id="<?php the_ID() ?>"
                data-group-id="<?php echo $question["question_id"]; ?>"
                data-voted-group="<?php echo isset($zombify_poll_results["groups"][$question["question_id"]]) ? $zombify_poll_results["groups"][$question["question_id"]] : 0 ?>">
               <div class="zf-answer js-zf-answer">
                   <div class="zf-checkbox-wrp"></div>
                   <div class="zf-poll-stat"></div>
                   <div class="zf-poll-stat_count"></div>
                   <div class="zf-answer_text">
                       <?php echo $answer["answer_text"]; ?>
                   </div>
               </div>
            </li>
        <?php
        }
     }
} else {
 echo 'Please login to show these poll';
}?>
</ol>```

I have a poll, the vote of which must be closed for guests.

<ol class="zf-structure-list zf-quiz_answer zf-text zf-clearfix">
    <?php
    if( isset( $question["answers"] ) ) {
        foreach ($question["answers"] as $answer) {
            ?>
            <li class="zf-answer-item <?php if (isset($_COOKIE["zf_poll_vote_ans_" . $answer["answer_id"]])) echo 'zf-selected'; ?>"
                data-voted="<?php echo isset($poll_results["answers"][$answer["answer_id"]]) ? $poll_results["answers"][$answer["answer_id"]] : 0 ?>"
                data-id="<?php echo $answer["answer_id"]; ?>" data-post-id="<?php the_ID() ?>"
                data-group-id="<?php echo $question["question_id"]; ?>"
                data-voted-group="<?php echo isset($zombify_poll_results["groups"][$question["question_id"]]) ? $zombify_poll_results["groups"][$question["question_id"]] : 0 ?>">
               <div class="zf-answer js-zf-answer">
                   <div class="zf-checkbox-wrp"></div>
                   <div class="zf-poll-stat"></div>
                   <div class="zf-poll-stat_count"></div>
                   <div class="zf-answer_text">
                       <?php echo $answer["answer_text"]; ?>
                   </div>
               </div>
            </li>
        <?php
        }
    } ?>
</ol>

How to make that polls show for the guest, but when you click on the zf-answer-item, nothing happened?

Thanks!

I have a poll, the vote of which must be closed for guests.

<ol class="zf-structure-list zf-quiz_answer zf-text zf-clearfix">
    <?php
    if( isset( $question["answers"] ) ) {
        foreach ($question["answers"] as $answer) {
            ?>
            <li class="zf-answer-item <?php if (isset($_COOKIE["zf_poll_vote_ans_" . $answer["answer_id"]])) echo 'zf-selected'; ?>"
                data-voted="<?php echo isset($poll_results["answers"][$answer["answer_id"]]) ? $poll_results["answers"][$answer["answer_id"]] : 0 ?>"
                data-id="<?php echo $answer["answer_id"]; ?>" data-post-id="<?php the_ID() ?>"
                data-group-id="<?php echo $question["question_id"]; ?>"
                data-voted-group="<?php echo isset($zombify_poll_results["groups"][$question["question_id"]]) ? $zombify_poll_results["groups"][$question["question_id"]] : 0 ?>">
               <div class="zf-answer js-zf-answer">
                   <div class="zf-checkbox-wrp"></div>
                   <div class="zf-poll-stat"></div>
                   <div class="zf-poll-stat_count"></div>
                   <div class="zf-answer_text">
                       <?php echo $answer["answer_text"]; ?>
                   </div>
               </div>
            </li>
        <?php
        }
    } ?>
</ol>

How to make that polls show for the guest, but when you click on the zf-answer-item, nothing happened?

Thanks!

Share Improve this question edited Jan 2, 2019 at 17:55 Tom J Nowell 61.2k7 gold badges79 silver badges150 bronze badges asked Jan 2, 2019 at 16:59 Grosso2020Grosso2020 1 1
  • How are you implementing polls? I'm guessing based on the data attributes you're using a polls JS library, but you never mention which one, how it's added, how it runs, etc etc. Also where does this data come from? WP doesn't come with polls out of the box, are you using a custom plugin? Where does the $question array come from? How do you determine what a guest is? – Tom J Nowell Commented Jan 2, 2019 at 17:55
Add a comment  | 

1 Answer 1

Reset to default 0

You can check user logged in with is_user_logged_in. This is a simple function to check user logged in or not. Can you try this?

<ol class="zf-structure-list zf-quiz_answer zf-text zf-clearfix">
    <?php
  if(is_user_logged_in()){
    if( isset( $question["answers"] ) ) {
        foreach ($question["answers"] as $answer) {
            ?>
            <li class="zf-answer-item <?php if (isset($_COOKIE["zf_poll_vote_ans_" . $answer["answer_id"]])) echo 'zf-selected'; ?>"
                data-voted="<?php echo isset($poll_results["answers"][$answer["answer_id"]]) ? $poll_results["answers"][$answer["answer_id"]] : 0 ?>"
                data-id="<?php echo $answer["answer_id"]; ?>" data-post-id="<?php the_ID() ?>"
                data-group-id="<?php echo $question["question_id"]; ?>"
                data-voted-group="<?php echo isset($zombify_poll_results["groups"][$question["question_id"]]) ? $zombify_poll_results["groups"][$question["question_id"]] : 0 ?>">
               <div class="zf-answer js-zf-answer">
                   <div class="zf-checkbox-wrp"></div>
                   <div class="zf-poll-stat"></div>
                   <div class="zf-poll-stat_count"></div>
                   <div class="zf-answer_text">
                       <?php echo $answer["answer_text"]; ?>
                   </div>
               </div>
            </li>
        <?php
        }
     }
} else {
 echo 'Please login to show these poll';
}?>
</ol>```

本文标签: phpHow to make a vote in the poll for registered users