Advertisement
Mimeobrad

archive-faqs.php

Oct 29th, 2021
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. <?php
  2. $categories = get_terms('faq_cat'); ?>
  3. <ul class="cat-list">
  4.   <li><a class="cat-list_item active" href="#!" data-slug="">All FAQS</a></li>
  5.   <?php foreach($categories as $category) : ?>
  6.     <li>
  7.       <a class="cat-list_item" href="#!" data-slug="<?= $category->slug; ?>">
  8.         <?= $category->name; ?>
  9.       </a>
  10.     </li>
  11.   <?php endforeach; ?>
  12. </ul>
  13.  
  14. <?php
  15.   $faqs = new WP_Query([
  16.    'post_type' => 'faqs',
  17.     'posts_per_page' => -1,
  18.     'order_by' => 'date',
  19.     'order' => 'desc',
  20. ]);
  21. ?>
  22.  
  23. <?php if($faqs->have_posts()): ?>
  24.   <ul class="project-tiles">
  25.     <?php
  26.       while($faqs->have_posts()) : $faqs->the_post();
  27.         the_title();
  28.       endwhile;
  29.     ?>
  30.   </ul>
  31.   <?php wp_reset_postdata(); ?>
  32. <?php endif; ?>
  33.  
  34. <script>
  35.   jQuery(document).ready(function($) {
  36.     $('.cat-list_item').on('click', function() {
  37.   $('.cat-list_item').removeClass('active');
  38.   $(this).addClass('active');
  39.  
  40.   $.ajax({
  41.     type: 'POST',
  42.     url: '/wp-admin/admin-ajax.php',
  43.     dataType: 'html',
  44.     data: {
  45.       action: 'filter_projects',
  46.       category: $(this).data('slug'),
  47.     },
  48.     success: function(res) {
  49.       $('.project-tiles').html(res);
  50.     }
  51.   })
  52. });
  53. });
  54. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement