PHP 28
Cpt testimonial module - dom structure By micha on 5th July 2023 04:14:25 PM
  1. $orderBy = get_field('testimonial_order');
  2. global $post;
  3.  
  4. $arguments = [
  5. 'post_type'      => 'testimonial',
  6. 'posts_per_page' => -1,
  7. 'order'          => $orderBy,
  8. ];
  9.  
  10. if ( $categories = get_field('testimonial_category') ) {
  11.   $arguments['tax_query'] = [
  12.   [
  13.   'taxonomy' => 'testimonial_tax',
  14.   'field'    => 'term_id',
  15.   'terms'    => $categories,
  16.   ]
  17.   ];
  18. }
  19.  
  20. if ( $orderby = get_field('testimonial_sort') ) {
  21.   $arguments['orderby'] = $orderby;
  22. }
  23.  
  24. $testimonial_query = new WP_Query( $arguments );
  25. if ( $testimonial_query->have_posts() ) {
  26.  
  27.  
  28.   $className = 'custom-testimonial-block testimonial-block';
  29.   if( !empty($block['className']) ) {
  30.     $className .= ' ' . $block['className'];
  31.   }
  32.  
  33.   $block_id = 'testimonials_'.$block['id'];
  34.  
  35.  
  36.   echo "<div class='$className'>";
  37.  
  38.   echo "<div class='swiper-container' id='$block_id'>";
  39.   echo "<div class='swiper-wrapper'>";
  40.  
  41.   $index = 0;
  42.  
  43.   while ( $testimonial_query->have_posts() ) {
  44.     $testimonial_query->the_post();
  45.  
  46.     $overline     = get_field('testimonial_overline', $post->ID);
  47.     $content      = get_field('testimonial_content', $post->ID);
  48.     $image        = get_field('testimonial_image', $post->ID);
  49.     $company      = get_field('testimonial_company_client', $post->ID);
  50.     $name         = get_field('testimonial_name', $post->ID);
  51.  
  52.     $index++;
  53.     $elementClass = 'testimonial-element';
  54.  
  55.     if ($index % 2 === 0) {
  56.       $elementClass .= ' even';
  57.     } else {
  58.       $elementClass .= ' odd';
  59.     }
  60.  
  61.     echo "<div class='swiper-slide'>";
  62.  
  63.     $__ = '';
  64.  
  65.       if(!empty($image)) {
  66.         $__  .= "<div class='image-container'>";
  67.         $__ .= get_img_set($image, 'relative', 25, ['type'=>'img']); //the function get_img_set is not implemented in this project, so you have to use the regular function from WP which you allready used with the image slider
  68.         $__ .= "</div>";
  69.       }
  70.  
  71.       $__ .= "<div class='content-container'>";
  72.       $__ .= "<div class='testimonial-title'>$overline</div>";
  73.       $__ .= "<div class='testimonial-text'>$content</div>";
  74.       $__ .= "<div class='testimonial-user'><span>$company</span>, $name</div>";
  75.       $__ .= "</div>";
  76.  
  77.     echo "<div class='$elementClass'>$__</div>";
  78.  
  79.     echo "</div>";
  80.  
  81.   }
  82.  
  83.   echo "</div>";
  84.   echo "</div>";
  85.  
  86.   echo "<div class='slider-prev slider-button' id='$block_id-prev'><span class='fal fa-angle-left'></span></div>";
  87.   echo "<div class='slider-pagination' id='$block_id-pagination'></div>";
  88.   echo "<div class='slider-next slider-button' id='$block_id-next'><span class='fal fa-angle-right'></span></div>";
  89.  
  90. }
  91.  
  92. <?php
  93. echo "</div>";

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.