Answer for every question
-
Is there a way to display the answers (wrong/correct) and the “wrong” texts for every question instead of at the end?
Thank you
m
-
Hi gattamelata, this can be done by adding some custom javascript.
How comfortable are you with editing your theme? If I sent you some code, would you be able to add it to your theme’s functions.php file?
Yep, i think i can handle it.
I’ll need to do it on a child theme i suppose.
Thanks a lotGreat, I’ll send you what you need and instructions soon
Here is what we need to do.
- Deactivate and delete HD Quiz (you will not lose any quiz data)
- Download, upload, and activate the beta version here.
- Edit
functions.phpof your theme (or child) and paste in the below code - clear your cache to ensure latest files load
function hdq_before_test($quizID) { ?> <script> jQuery(window).load(function() { // when an answer is selected jQuery(".hdq_label_answer").click(function(){ // check if this question has already been answered let p = jQuery(this).parent().parent(); if(jQuery(p).hasClass("hdq_answered")){ return false; } else { jQuery(p).addClass("hdq_answered"); // check to see if answer was right console.log(jQuery(this)) if(jQuery(this)[0].children[0].children[0].value == 1){ jQuery(p).addClass("hdq_answered_correct"); jQuery(this).addClass("hdq_correct"); } else { jQuery(p).addClass("hdq_answered_incorrect"); jQuery(this).addClass("hdq_wrong"); } jQuery(p).find(".hdq_question_after_text").fadeIn(); } }); }); </script> <?php } add_action('hdq_before', 'hdq_before_test');The beta version I had you download includes custom actions and hooks. The one we are using allows us to insert any custom code to the start of each quiz load. We could have inserted the same jQuery to your footer.php file directly without the beta version, but then the code would be on all pages instead of just ones with a quiz on it.
What the above javascript code does is first check to see if an answer is selected. It then marks the question as “complete” so that changing your answer will not do anything. It will then mark the answer as correct or incorrect, and display the additional information if there was any.
Please note that although the above code will work for your purposes, it’s not perfect (for example, you still have to select “finish” to see your full results), but it should be more than enough to get you on the right track.
Wow,
thank you mate, I owe you a favor.m
It’s working great.
The only problem in that now every time i update a question it is displayed like this:■ quando-avviene-la-maggior-parte-dei-furti?
instead of:
■ quando avviene la maggior parte dei furti?
Is there something i can do?
Hi gattamelata,
this may be a bug in the beta version. A fix will be released very soon for it!Hi,
any news?Yup!
The release will be this weekend – keep an eye out for it!
Hi Harmonic, is there a way to show the right answer as well if you get it wrong, I think this feature is awesome btw
The topic ‘Answer for every question’ is closed to new replies.