Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Create mini Quiz with one Word and three possible Definitions WordPress

  • SOLVED

I would like to create a quiz similar to "Our Quiz" at [[LINK href="http://tinyurl.com/6c48bdl"]]http://tinyurl.com/6c48bdl[[/LINK]] where people can click a synonym or definition for a word as the correct answer. Every time the page reloads a new word + possible definitions is loaded. When a possible definition is clicked a popup - jQuery - shows you if the answer is correct or not. It also offers to load another quiz word when the answer was correct. Question is, how to do this in a convenient way in WordPress?

Answers (4)

2011-09-12

Abdessamad Idrissi answers:

You would do this in 4 steps:
1. Create a page template for your <em>word-of-the-day</em> page by inserrting in your functions.php this code:

// Prepare the page
$my_page = array(
'post_status' => 'publish',
'post_type' => 'page',
'post_author' => 1,
'post_name' => $page["post_name"],
'post_title' => $page["post_title"]
);

// Insert the page into the database
$page_id = wp_insert_post($my_page);

// Assign the page template to the new page
update_post_meta($page_id, '_wp_page_template', 'word-of-the-day.php');


2. Inside your theme create a file with name <em>word-of-the-day.php</em>

3. In <em>word-of-the-day.php</em> you will need to: get random post and get fake posts too by using :
<ul id="quiz">
<?php

// save its ID
$question_id = '';

// get the question word
query_posts( 'orderby=rand&posts_per_page=1' );
if ( have_posts() ) :
while ( have_posts() ) : the_post();
$question_id = get_the_ID();
?><li>What does it mean <a href="<?php the_permalink(); ?>" class="question"><?php the_title() ?></a>?</li><?php
endwhile;
endif;

// reset the previous query
wp_reset_query();

// get 2 fake answers
$args = array( 'numberposts' => 2, 'exclude'=> $question_id );
$fake_answers = get_posts( $args );

// Now prepare the answers
echo '<ul id="sub_quiz">';

$args = array(
'orderby' => 'rand',
'post__in' => array($question_id, $fake_answers[0]->ID, $fake_answers[1]->ID),
'posts_per_page' => 3
);

query_posts( $args );
if ( have_posts() ) :
while ( have_posts() ) : the_post();
?><li>.<a href="#" class="answer" <?php if(get_the_ID() == $question_id) echo 'id="correct"'; ?>'><?php the_content(); ?></a></li><?php
endwhile;
endif;
wp_reset_query();

echo '</ul';
?>
</ul>



4. Add a jQuery call inside this post to manage the functionality of the quiz by playing with the class names of the links:
<script>
jQuery(document).ready(function($){

$("a.answer").click(function(){
if( $(this).attr('id') == 'correct') {
alert('correct!');
}
return false;
});
});
</script>


well that's it! but as Julio, fahd and ryan said; this is broad question better if separated to parts because it deals with wordpress + jquery + ajay

hope it helps :)


rhand comments:

Thanks for all the feedback. Will play with all this a bit today or tomorrow. I know it can be quite a bit of work, but I need to make sure it will all fit within the budget. I wonder what a fully working plugin would take. Perhaps four questions of $25, perhaps more...

2011-09-12

Julio Potier answers:

Hello

Your needs is a specific development/plugin and requires specifications.

I don't think someone can do this in 1 hour.

I suggested a $100 min price.

2011-09-12

Fahad Murtaza answers:

I am seconding Julio here.

2011-09-12

Ryan Hellyer answers:

This question is way too broad. Perhaps narrow it down to specific questions about parts of the plugin you wish to build rather than a generic question about how to build the whole thing.