tpl_view_courses - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of tpl_view_courses.php

  1. <?php
  2. /*
  3. Template Name: Шаблон Категории курсов
  4. */
  5. ?>
  6.  
  7. <? get_header(); ?>
  8.  
  9.     <div class="rbt-page-banner-wrapper">
  10.         <!-- Start Banner BG Image  -->
  11.         <div class="rbt-banner-image"></div>
  12.         <!-- End Banner BG Image  -->
  13.         <div class="rbt-banner-content">
  14.             <!-- Start Banner Content Top  -->
  15.             <div class="rbt-banner-content-top">
  16.                 <div class="container">
  17.                     <div class="row">
  18.                         <div class="col-lg-12">
  19.                             <!-- Start Breadcrumb Area  -->
  20.                             <ul class="page-list">
  21.                                 <li class="rbt-breadcrumb-item"><a href="index.html">Home</a></li>
  22.                                 <li>
  23.                                     <div class="icon-right"><i class="feather-chevron-right"></i></div>
  24.                                 </li>
  25.                                 <li class="rbt-breadcrumb-item active">All Courses</li>
  26.                             </ul>
  27.                             <!-- End Breadcrumb Area  -->
  28.  
  29.                             <div class=" title-wrapper">
  30.                                 <h1 class="title mb--0">All Courses</h1>
  31.                                 <a href="#" class="rbt-badge-2">
  32.                                     <div class="image">????</div> 50 Courses
  33.                                 </a>
  34.                             </div>
  35.  
  36.                             <p class="description">Courses that help beginner designers become true unicorns. </p>
  37.                         </div>
  38.                     </div>
  39.                 </div>
  40.             </div>
  41.             <!-- End Banner Content Top  -->
  42.             <!-- Start Course Top  -->
  43.             <div class="rbt-course-top-wrapper mt--40">
  44.                 <div class="container">
  45.                     <div class="row g-5 align-items-center">
  46.                         <div class="col-lg-5 col-md-12">
  47.                             <div class="rbt-sorting-list d-flex flex-wrap align-items-center">
  48.                                 <div class="rbt-short-item switch-layout-container">
  49.                                     <ul class="course-switch-layout">
  50.                                         <li class="course-switch-item"><button class="rbt-grid-view active" title="Grid Layout"><i class="feather-grid"></i> <span class="text">Grid</span></button></li>
  51.                                         <li class="course-switch-item"><button class="rbt-list-view" title="List Layout"><i class="feather-list"></i> <span class="text">List</span></button></li>
  52.                                     </ul>
  53.                                 </div>
  54.                                 <div class="rbt-short-item">
  55.                                     <span class="course-index">Showing 1-9 of <span id="count-all-courses">0</span> results</span>
  56.                                 </div>
  57.                             </div>
  58.                         </div>
  59.                         <div class="col-lg-7 col-md-12">
  60.                             <div class="rbt-sorting-list d-flex flex-wrap align-items-center justify-content-start justify-content-lg-end">
  61.                                 <div class="rbt-short-item">
  62.                                     <div class="filter-select">
  63.                                         <span class="select-label d-block">Short By</span>
  64.                                         <div class="filter-select rbt-modern-select search-by-category">
  65.                                             <div class="dropdown bootstrap-select"><select data-size="7" class="" tabindex="null">
  66.                                                 <option>Default</option>
  67.                                                 <option>Latest</option>
  68.                                                 <option>Popularity</option>
  69.                                                 <option>Trending</option>
  70.                                                 <option>Price: low to high</option>
  71.                                                 <option>Price: high to low</option>
  72.                                             </select>
  73.                                             <div class="dropdown-menu" style="overflow: hidden;"><div class="inner show" role="listbox" id="bs-select-1" tabindex="-1" aria-activedescendant="bs-select-1-0" style="overflow-y: auto;"><ul class="dropdown-menu inner show" role="presentation" style="margin-top: 0px; margin-bottom: 0px;"><li class="selected active"><a role="option" class="dropdown-item active selected" id="bs-select-1-0" tabindex="0" aria-setsize="6" aria-posinset="1" aria-selected="true"><span class="text">Default</span></a></li><li><a role="option" class="dropdown-item" id="bs-select-1-1" tabindex="0"><span class="text">Latest</span></a></li><li><a role="option" class="dropdown-item" id="bs-select-1-2" tabindex="0"><span class="text">Popularity</span></a></li><li><a role="option" class="dropdown-item" id="bs-select-1-3" tabindex="0"><span class="text">Trending</span></a></li><li><a role="option" class="dropdown-item" id="bs-select-1-4" tabindex="0"><span class="text">Price: low to high</span></a></li><li><a role="option" class="dropdown-item" id="bs-select-1-5" tabindex="0"><span class="text">Price: high to low</span></a></li></ul></div></div>
  74.                                         </div>
  75.                                         </div>
  76.                                     </div>
  77.                                 </div>
  78.                             </div>
  79.                         </div>
  80.                     </div>
  81.                 </div>
  82.             </div>
  83.             <!-- End Course Top  -->
  84.         </div>
  85.     </div>
  86.  
  87.  
  88.     <div class="rbt-section-overlayping-top rbt-section-gapBottom">
  89.         <div class="container">
  90.             <div class="row row--30 gy-5">
  91.                 <div class="col-lg-3 order-2 order-lg-1">
  92.                     <aside class="rbt-sidebar-widget-wrapper">
  93.  
  94.                         <!-- Start Widget Area  -->
  95.                         <div class="rbt-single-widget rbt-widget-search">
  96.                             <div class="inner">
  97.                                 <form action="#" class="rbt-search-style-1">
  98.                                     <input type="text" placeholder="Search Courses">
  99.                                     <button class="search-btn"><i class="feather-search"></i></button>
  100.                                 </form>
  101.                             </div>
  102.                         </div>
  103.                         <!-- End Widget Area  -->
  104.  
  105.                         <!-- Start Widget Area  -->
  106.                         <div class="rbt-single-widget rbt-widget-categories has-show-more">
  107.                             <div class="inner">
  108.                                 <h4 class="rbt-widget-title">Categories</h4>
  109.                                 <ul class="rbt-sidebar-list-wrapper categories-list-check has-show-more-inner-content">
  110.                                 <script>
  111.                                     let arrayCatFilter = [];
  112.                                     let rate_ = '';
  113.                                     let teacher_ = [];
  114.                                     let price_ = [];
  115.                                     let levels_ = [];
  116.                                     function addFilter(arr, element){
  117.                                         id = arr.indexOf(element);
  118.                                         if(id==-1){
  119.                                             arr.push(element);
  120.                                         } else {
  121.                                             arr.splice(id, 1);
  122.                                         }
  123.                                         return arr;
  124.                                     }
  125.                                     
  126.                                 </script>
  127.                                     <?
  128.                                         $categories = get_categories( array(
  129.                                             'orderby'      => 'name',
  130.                                             'order'        => 'ASC',
  131.                                             'hide_empty'   => 0,
  132.                                             'exclude'      => array(15, 16),
  133.                                             'include'      => '',
  134.                                         ));
  135.                                         $count = 1;
  136.                                         foreach( $categories as $cat ){
  137.                                             if($cat->parent != 0):?>
  138.                                                 <li class="rbt-check-group">
  139.                                                     <input id="cat-list-<?=$count?>" type="checkbox" name="cat-list-<?=$count?>">
  140.                                                     <label for="cat-list-<?=$count?>" onclick="arrayCatFilter=addFilter(arrayCatFilter, <?=$cat->term_id?>);ViewCourses();"><?=$cat->name?><span class="rbt-lable count"><?=$cat->count?></span></label>
  141.                                                 </li>
  142.                                                 <?$count++;?>
  143.                                             <?endif;?>
  144.                                         <?}?>
  145.                                 </ul>
  146.                             </div>
  147.                             <div class="rbt-show-more-btn">Show More</div>
  148.                         </div>
  149.                         <!-- End Widget Area  -->
  150.  
  151.                         <!-- Start Widget Area  -->
  152.                         <div class="rbt-single-widget rbt-widget-rating">
  153.                             <div class="inner">
  154.                                 <h4 class="rbt-widget-title">Ratings</h4>
  155.                                 <ul class="rbt-sidebar-list-wrapper rating-list-check">
  156.                                     <li class="rbt-check-group">
  157.                                         <input id="cat-radio-1" type="radio" name="rbt-radio">
  158.                                         <label for="cat-radio-1" onclick="rate_=5;ViewCourses();">
  159.                                             <span class="rating">
  160.                             <i class="fas fa-star"></i>
  161.                             <i class="fas fa-star"></i>
  162.                             <i class="fas fa-star"></i>
  163.                             <i class="fas fa-star"></i>
  164.                             <i class="fas fa-star"></i>
  165.                         </span>
  166.                                             <span class="rbt-lable count">5</span>
  167.                                         </label>
  168.                                     </li>
  169.                                     <li class="rbt-check-group">
  170.                                         <input id="cat-radio-2" type="radio" name="rbt-radio">
  171.                                         <label for="cat-radio-2" onclick="rate_=4;ViewCourses();">
  172.                                             <span class="rating">
  173.                             <i class="fas fa-star"></i>
  174.                             <i class="fas fa-star"></i>
  175.                             <i class="fas fa-star"></i>
  176.                             <i class="fas fa-star"></i>
  177.                             <i class="off fas fa-star"></i>
  178.                         </span>
  179.                                             <span class="rbt-lable count">4</span>
  180.                                         </label>
  181.                                     </li>
  182.                                     <li class="rbt-check-group">
  183.                                         <input id="cat-radio-3" type="radio" name="rbt-radio">
  184.                                         <label for="cat-radio-3" onclick="rate_=3;ViewCourses();">
  185.                                             <span class="rating">
  186.                             <i class="fas fa-star"></i>
  187.                             <i class="fas fa-star"></i>
  188.                             <i class="fas fa-star"></i>
  189.                             <i class="off fas fa-star"></i>
  190.                             <i class="off fas fa-star"></i>
  191.                         </span>
  192.                                             <span class="rbt-lable count">3</span>
  193.                                         </label>
  194.                                     </li>
  195.                                     <li class="rbt-check-group">
  196.                                         <input id="cat-radio-4" type="radio" name="rbt-radio">
  197.                                         <label for="cat-radio-4" onclick="rate_=2;ViewCourses();">
  198.                                             <span class="rating">
  199.                             <i class="fas fa-star"></i>
  200.                             <i class="fas fa-star"></i>
  201.                             <i class="off fas fa-star"></i>
  202.                             <i class="off fas fa-star"></i>
  203.                             <i class="off fas fa-star"></i>
  204.                         </span>
  205.                                             <span class="rbt-lable count">2</span>
  206.                                         </label>
  207.                                     </li>
  208.  
  209.                                     <li class="rbt-check-group">
  210.                                         <input id="cat-radio-5" type="radio" name="rbt-radio">
  211.                                         <label for="cat-radio-5" onclick="rate_=1;ViewCourses();">
  212.                                             <span class="rating">
  213.                             <i class="fas fa-star"></i>
  214.                             <i class="off fas fa-star"></i>
  215.                             <i class="off fas fa-star"></i>
  216.                             <i class="off fas fa-star"></i>
  217.                             <i class="off fas fa-star"></i>
  218.                         </span>
  219.                                             <span class="rbt-lable count">1</span>
  220.                                         </label>
  221.                                     </li>
  222.                                 </ul>
  223.                             </div>
  224.                         </div>
  225.                         <!-- End Widget Area  -->
  226.  
  227.                         <!-- Start Widget Area  -->
  228.                         <div class="rbt-single-widget rbt-widget-instructor">
  229.                             <div class="inner">
  230.                                 <h4 class="rbt-widget-title">Instructors</h4>
  231.                                 <ul class="rbt-sidebar-list-wrapper instructor-list-check">
  232.                                     <?
  233.                                         $tags = get_tags(array(
  234.                                             'hide_empty' => false,
  235.                                             'exclude'    => array(13, 17),
  236.                                         ));
  237.                                         $arrayTeacher = [];
  238.                                         foreach($tags as $tag){
  239.                                             $my_posts = get_posts( array(
  240.                                                 'tag' => $tag->slug,
  241.                                             ) );
  242.                                             $cerrentArr = [];
  243.                                             foreach($my_posts as $post){
  244.                                                 $teacherName = get_field('name_teacher', $post->ID);
  245.                                                 if($teacherName==''){continue;}
  246.                                                 if (array_key_exists($teacherName, $arrayTeacher)){
  247.                                                     $arrayTeacher[$teacherName] = $arrayTeacher[$teacherName] + 1;
  248.                                                 } else {
  249.                                                     
  250.                                                     $arrayTeacher[$teacherName] = 1;
  251.                                                 }
  252.                                             }
  253.                                         }
  254.                                         $count = 1;
  255.                                         foreach($arrayTeacher as $key=>$value){?>
  256.                                             <li class="rbt-check-group">
  257.                                                 <input id="ins-list-<?=$count?>" type="checkbox" name="ins-list-<?=$count?>">
  258.                                                 <label for="ins-list-<?=$count?>" onclick="teacher_=addFilter(teacher_, '<?=$key?>');ViewCourses();"><?=$key?> <span class="rbt-lable count"><?=$value?></span></label>
  259.                                             </li>
  260.                                             <?$count++;?>
  261.                                         <?}?>
  262.                                 </ul>
  263.                             </div>
  264.                         </div>
  265.                         <!-- End Widget Area  -->
  266.  
  267.                         <!-- Start Widget Area  -->
  268.                         <div class="rbt-single-widget rbt-widget-prices">
  269.                             <div class="inner">
  270.                                 <h4 class="rbt-widget-title">Prices</h4>
  271.                                 <ul class="rbt-sidebar-list-wrapper prices-list-check">
  272.                                     <?
  273.                                         $arrFilter = array(
  274.                                             'All' => 0,
  275.                                             'Free' => 0,
  276.                                             'Paid' => 0,
  277.                                         );
  278.                                         $tags = get_tags(array(
  279.                                             'hide_empty' => false,
  280.                                             'exclude'    => array(13, 17),
  281.                                         ));
  282.                                         foreach($tags as $tag){
  283.                                             $my_posts = get_posts( array(
  284.                                                 'tag' => $tag->slug,
  285.                                             ) );
  286.                                             foreach($my_posts as $post){
  287.                                                 $priceFilter = get_field('price_filter', $post->ID);
  288.                                                 if($priceFilter==''){continue;}
  289.                                                 if (array_key_exists($priceFilter, $arrFilter)){
  290.                                                     $arrFilter[$priceFilter] = $arrFilter[$priceFilter] + 1;
  291.                                                 }
  292.                                             }
  293.                                         }
  294.                                         $count = 1;
  295.                                     ?>
  296.                                     <?foreach ($arrFilter as $key => $value):?>
  297.                                         <li class="rbt-check-group">
  298.                                             <input id="prices-list-<?=$count;?>" type="checkbox" name="prices-list-<?=$count;?>">
  299.                                             <label for="prices-list-<?=$count;?>" onclick="price_=addFilter(price_, '<?=$key?>');ViewCourses();"><?=$key?> <span class="rbt-lable count"><?=$value;?></span></label>
  300.                                         </li>
  301.                                         <?$count++;?>
  302.                                     <?endforeach;?>
  303.                                 </ul>
  304.                             </div>
  305.                         </div>
  306.                         <!-- End Widget Area  -->
  307.  
  308.                         <!-- Start Widget Area  -->
  309.                         <div class="rbt-single-widget rbt-widget-lavels">
  310.                             <div class="inner">
  311.                                 <h4 class="rbt-widget-title">Levels</h4>
  312.                                 <ul class="rbt-sidebar-list-wrapper lavels-list-check">
  313.                                 <?
  314.                                         $arrFilter = array(
  315.                                             'All Levels' => 0,
  316.                                             'Beginner' => 0,
  317.                                             'Intermediate' => 0,
  318.                                             'Expert' => 0,
  319.                                         );
  320.                                         $tags = get_tags(array(
  321.                                             'hide_empty' => false,
  322.                                             'exclude'    => array(13, 17),
  323.                                         ));
  324.                                         foreach($tags as $tag){
  325.                                             $my_posts = get_posts( array(
  326.                                                 'tag' => $tag->slug,
  327.                                             ) );
  328.                                             foreach($my_posts as $post){
  329.                                                 $levelFilter = get_field('level_filter', $post->ID);
  330.                                                 if($levelFilter==''){continue;}
  331.                                                 if (array_key_exists($levelFilter, $arrFilter)){
  332.                                                     $arrFilter[$levelFilter] = $arrFilter[$levelFilter] + 1;
  333.                                                 }
  334.                                             }
  335.                                         }
  336.                                         $count = 1;
  337.                                     ?>
  338.                                     <?foreach ($arrFilter as $key => $value):?>
  339.                                         <li class="rbt-check-group">
  340.                                             <input id="lavels-list-<?=$count;?>" type="checkbox" name="lavels-list-<?=$count;?>">
  341.                                             <label for="lavels-list-<?=$count;?>" onclick="levels_=addFilter(levels_, '<?=$key?>');ViewCourses();"><?=$key?><span class="rbt-lable count"><?=$value;?></span></label>
  342.                                         </li>
  343.                                         <?$count++;?>
  344.                                     <?endforeach;?>
  345.                                 </ul>
  346.                             </div>
  347.                         </div>
  348.                         <!-- End Widget Area  -->
  349.  
  350.                     </aside>
  351.                 </div>
  352.                 <div class="col-lg-9 order-1 order-lg-2">
  353.                     <div id="ajax-view-courses" class="rbt-course-grid-column active-grid-view">
  354.                     <script>
  355.                         let pageCount = 0;
  356.                         let pageNow = 1;
  357.                         let pageLast = 3;
  358.                         let arrResponse = [];
  359.                         function ViewCourses(){
  360.                             $.ajax({
  361.                                 type: "POST",
  362.                                 url: 'http://kursy.existparts.ru/wp-admin/admin-ajax.php',
  363.                                 data: {
  364.                                     action : 'view_courses',
  365.                                     categories_: arrayCatFilter,
  366.                                     rate_: rate_,
  367.                                     teacher_: teacher_,
  368.                                     price_: price_,
  369.                                     levels_: levels_
  370.                                 },
  371.                                 success: function (response) {
  372.                                     arrResponse = response.split('|');
  373.                                     let lengthArrResponse = arrResponse.length;
  374.                                     pageCount = Math.round(lengthArrResponse / 9);
  375.                                     if(pageCount<4){
  376.                                         pageLast = pageCount;
  377.                                     }
  378.                                     let string = '';
  379.                                     for(let i=0;i<9;i++){
  380.                                         if (arrResponse[i]==undefined){break;}
  381.                                         string += arrResponse[i];
  382.                                     }
  383.                                     $("#count-all-courses").html(lengthArrResponse);
  384.                                     $("#ajax-view-courses").html(string);
  385.                                     
  386.                                 }
  387.                             });
  388.                         }
  389.                         ViewCourses();
  390.                     </script>
  391.  
  392.                     </div>
  393.  
  394.                     <div class="row">
  395.                         <div class="col-lg-12 mt--60">
  396.                             <nav>
  397.                                 <ul id="paginator-gene" class="rbt-pagination">
  398.                                     <script>
  399.                                         function generatePagePaginator(page){
  400.                                             let arr = arrResponse.slice((page-1)*9, page*9);
  401.                                             let string = '';
  402.                                             for(let i=0;i<9;i++){
  403.                                                 if (arr[i]==undefined){break;}
  404.                                                 string += arr[i];
  405.                                             }
  406.                                             $("#ajax-view-courses").html(string);
  407.                                             let pagiantion = document.querySelectorAll("#paginator-gene li");
  408.                                             let pagiantionLen = pagiantion.length;
  409.                                             for(let i=0;i<pagiantionLen;i++){
  410.                                                 pagiantion[i].className = ''
  411.                                             }
  412.                                             document.querySelector('#page-'+page).className = 'active';
  413.                                         }
  414.  
  415.                                         function movePaginator(move){
  416.                                             pageNow += move;
  417.                                             pageLast += move;
  418.                                             return pageNow, pageLast
  419.                                         }
  420.  
  421.                                         function paginatorGenerate(){
  422.                                             let textResult = '';
  423.                                             if (pageNow!=1){
  424.                                                 textResult += '<li><a href="#paginator-gen" onclick="generatePagePaginator('+pageNow+');movePaginator(-1);paginatorGenerate();" aria-label="Previous"><i class="feather-chevron-left"></i></a></li>';
  425.                                             }
  426.  
  427.                                             textResult += '<li id="page-'+ pageNow +'" class="active"><a href="#paginator-gen" onclick="generatePagePaginator('+ pageNow +');">' + pageNow + '</a></li>';
  428.                                             for(let i=pageNow+1;i<pageLast+1;i++){
  429.                                                 textResult += '<li id="page-'+ i +'"><a href="#paginator-gen" onclick="generatePagePaginator('+ i +');">' + i + '</a></li>';
  430.                                             }
  431.  
  432.                                             if (pageNow<pageCount){
  433.                                                 textResult += '<li><a href="#paginator-gene" onclick="generatePagePaginator('+pageNow+');movePaginator(1);paginatorGenerate();" aria-label="Next"><i class="feather-chevron-right"></i></a></li>';
  434.                                             }
  435.                                             $("#paginator-gene").html(textResult);
  436.                                         }
  437.                                         paginatorGenerate();
  438.                                     </script>
  439.                                 </ul>
  440.                             </nav>
  441.                         </div>
  442.                     </div>
  443.  
  444.                 </div>
  445.             </div>
  446.         </div>
  447.     </div>
  448.  
  449. <?
  450. the_content();
  451.  
  452. get_footer();
  453.  
  454. ?>
  455.  
File Description
  • tpl_view_courses
  • PHP Code
  • 28 Sep-2023
  • 27.07 Kb
You can Share it: