Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Template Name: Checklist
- */
- get_header();
- ?>
- <script>
- var URI = "<?php echo get_template_directory_uri(); ?>/";
- jQuery(document).ready(function($) {
- $('.checklist-listing input').change(function(event) {
- var data = {};
- data[$(this).attr("name")] = $(this).is(':checked');
- $.ajax({
- url: URI+"checklist-ajax.php",
- type: 'POST',
- data: data,
- })
- .done(function( data, textStatus, jqXHR ) {
- });
- });
- });
- </script>
- <div style="width: 100%;">
- <?php
- //Cargar checklist del usuario
- $user_ID = get_current_user_id();
- $checklist = unserialize(get_user_meta($user_ID, "checklist", true));
- $esNuevo = false;
- if(!$checklist){
- $checklist = array();
- $esNuevo = true;
- }
- // Define the query y obtener todos los items
- $args = array(
- 'post_type' => 'checklist'
- );
- $query = new WP_Query( $args );
- $checklistArray = array();
- if($query->have_posts()):
- ?>
- <ul class="">
- <?php
- while ( $query->have_posts() ) : $query->the_post(); ?>
- <?php
- if(array_key_exists("checklist-".get_the_ID(), $checklist)){
- $checklistArray["checklist-".get_the_ID()] = $checklist["checklist-".get_the_ID()];
- }else{
- $checklistArray["checklist-".get_the_ID()] = false;
- }
- ?>
- <li class="checklist-listing" id="post-<?php the_ID(); ?>">
- <input type="checkbox" name="checklist-<?php the_ID(); ?>" id="checklist-id-<?php the_ID(); ?>" <?php echo (strlen($checklistArray["checklist-".get_the_ID()])>0) ? "checked='checked'" : ""; ?>> <label for="checklist-id-<?php the_ID(); ?>"><?php the_title(); ?></label>
- </li>
- <?php endwhile; ?>
- </ul>
- <?php endif; ?>
- <?php if($esNuevo) add_user_meta( $user_ID, "checklist", serialize($checklistArray)); ?>
- </div>
- <?php
- get_footer();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement