HD Quiz

Pagination Function for Questions

Published: March 17, 2025
Support status: closed

Is there an alternative way to enable pagination for all questions in the updated version of hd-quiz, since the hdq_print_jPaginate($quiz_ID) function appears to be missing from the latest update of hd-quiz/includes/template.php?

thread author: Asad

Hi Asad,
first, HD Quiz still includes the hdq_print_jPaginate function. It is located on line 465 of ./includes/functions.php and it is actively used to print out pagination functions.

HOWEVER, I’m not sure how you were using or calling this function before, but I do not recommend forcing pagination through this.

Instead, here is some simple code that will a) tell HD Quiz to run a custom JS function once it initializes, and b) prints that custom function to pages with a quiz. What this custom function does is adds the necessary pagination markup to all questions (except the first question).

function Asad_hdq_on_init($data)
{
    array_push($data->hdq_init, "Asad_hdq_on_init");
    return $data;
}
add_action("hdq_init", "Asad_hdq_on_init", 10, 1);

function Asad_hdq_after($quizID)
{
?>
    <script>
        function Asad_hdq_on_init() {
            const html = `            
<div class="hdq_jPaginate">
    <div class="hdq_hidden hdq_prev_button hdq_button hdq_kb" role="button" tabindex="0">${HDQ.VARS.settings.translate_next}</div>
    <div class="hdq_next_button hdq_jPaginate_button hdq_button hdq_kb" role="button" tabindex="0">${HDQ.VARS.settings.translate_next}</div>
</div>`;
            const questions = document.getElementsByClassName("hdq_question");
            for (let i = 1; i < questions.length; i++) {
                questions[i].insertAdjacentHTML("beforebegin", html);
            }
        }
    </script>
<?php
}
add_action("hdq_after", "Asad_hdq_after", 10, 1);

This code can be added to your theme’s functions.php file. Just make sure to backup the file first in case you make a mistake adding the code.

17 March 2025 — 14:58 support admin - Dylan

Respond to thread

This thread has been closed / marked as resolved.
You can reply to this thread, but it might be better to start a new thread if you need help
.

You can also upload images to imgur and paste the links here. Just make sure that your images don't include any sensitive information.

Submit