Advertisement
shutupchigo

Testimonials_accordion

Dec 11th, 2018
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.90 KB | None | 0 0
  1. <?php get_header();?>
  2. <style>
  3. .accordion {
  4.   background-color: #eee;
  5.   color: #444;
  6.   cursor: pointer;
  7.   padding: 18px;
  8.   width: 100%;
  9.   border: none;
  10.   text-align: left;
  11.   outline: none;
  12.   font-size: 15px;
  13.   transition: 0.4s;
  14.   margin-bottom:20px;
  15. }
  16.  
  17. .active, .accordion:hover {
  18.   background-color: #ccc;
  19. }
  20.  
  21. .panel {
  22.   padding: 0 18px;
  23.   display: none;
  24.   background-color: white;
  25.   overflow: hidden;
  26. }
  27. </style>
  28. <div class="container-fluid testimonial-header">
  29.     <div class="row">
  30.         <div class="col-lg-12 text-center">
  31.             <h1>Testimonials</h1>
  32.         </div>
  33.     </div>
  34. </div>
  35. <div class="container testimonial-content">
  36.     <div class="block-1">
  37.         <h2 class="heading">Delivering Exceptional Customer Service</h2>
  38.         <p class="sub-heading">Being locally owned and operated, our objective is to provide exceptional client service delivered by our professional team. We take great pride in building homes that are beyond expectation, on time and on budget.</p>
  39.     </div>
  40. </div>
  41. <div class="container-fluid py-5 archive-testimonial">
  42.     <div class="container">
  43.         <div class="row">
  44.             <div class="col-lg-12">
  45.             <?php
  46. global $wpdb;
  47.  
  48. $posts = $wpdb->posts;
  49.  
  50. //Get all unique years as "years" from posts where post type is equal to testimonials
  51.  
  52. $sql = "SELECT DISTINCT(YEAR(`post_date`)) as years FROM $posts WHERE post_type = 'testimonials' ORDER BY years DESC"; //Get all post year list by DESC
  53.  
  54.  
  55. //Loop through all results and use date_query param https://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters
  56.  
  57.  
  58. $result = $wpdb->get_results($sql);
  59.  
  60. foreach($result as $rs) { ?>
  61.     <button class="accordion"><?php echo $rs->years ;?></button>
  62.     <?php $args = array(
  63.         'post_type' => 'testimonials',
  64.         'post_per_page'=> -1,
  65.         'post_status' => 'publish',
  66.         'orderby'   => 'date',
  67.         'order' => 'DESC',
  68.         'date_query' => array(array(
  69.             'year'=> $rs->years,
  70.         ),),
  71.  
  72.     );
  73.  
  74.      $loop = new WP_Query($args);
  75.  
  76.      if($loop->have_posts()) {
  77.  
  78.         while($loop->have_posts()) : $loop->the_post(); ?>
  79.             <div class="panel testimonial-grid-archive testimonial-loop-ah">
  80.                 <div>
  81.                     <?php
  82.                         if(has_post_thumbnail()) { ?>
  83.                             <div style="text-center">
  84.                                         <div class="testimonial-image-aden" style="background-image:url('<?php echo the_post_thumbnail_url(); ?>');"> </div>
  85.                                     </div>
  86.                                 <?php } else { ?>
  87.                                     <div class="testimonial-image-aden placeholder-testimonial-image"> </div>
  88.                                 <?php }
  89.                                 ?>
  90.                             </div>
  91.                 <div class="testimonial-content">
  92.                     <p class="testimonial-highlight"><?php echo the_field('testimonial_highlight') ;?></p>
  93.                     <p><img class="star-ratings-ah" src="<?php echo get_stylesheet_directory_uri(); ?>/assets/images/stars.png" alt=""></p>
  94.                     <div class="testimonial-text-ah">" <?php the_field('testimonial_text'); ?> "</div>          
  95.                     <p class="person-title-archive">- <?php the_title() ;?></p>
  96.                 </div>
  97.             </div>
  98.  
  99.            
  100.         <?php endwhile;
  101.  
  102.      }
  103. }
  104.             ?>
  105.             </div>
  106.         </div>
  107.     </div>
  108. </div>
  109. <script>
  110. var acc = document.getElementsByClassName("accordion");
  111. var i;
  112.  
  113. for (i = 0; i < acc.length; i++) {
  114.   acc[i].addEventListener("click", function() {
  115.     this.classList.toggle("active");
  116.     var panel = this.nextElementSibling;
  117.     if (panel.style.display === "block") {
  118.       panel.style.display = "none";
  119.     } else {
  120.       panel.style.display = "block";
  121.     }
  122.   });
  123. }
  124. </script>
  125. <?php get_footer();?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement