Advertisement
Osama_Mersal

Untitled

Jan 22nd, 2025
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. <?php
  2. /**
  3. * Template name: Projects page
  4. *
  5. * This is the most generic template file in a WordPress theme
  6. * and one of the two required files for a theme (the other being style.css).
  7. * It is used to display a page when nothing more specific matches a query.
  8. * E.g., it puts together the home page when no home.php file exists.
  9. *
  10. * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
  11. *
  12. * @package project-starter
  13. */
  14.  
  15. get_header();
  16. $get_category = "";
  17. if (isset($_GET['category'])) {
  18. // sanitize the tag
  19. $get_category = sanitize_text_field($_GET['category']);
  20. }
  21. ?>
  22.  
  23. <div id="title-holder">
  24. <h1><?php the_title();?></h1>
  25. </div>
  26.  
  27. <div class="row">
  28. <div id="project-filter-holder" class="filter-holder col col-12 hover-anim-holder">
  29. <a href="<?php echo (ICL_LANGUAGE_CODE=="en") ? '/projects/':'/projecten/';?>" <?php if ($get_category=="") { ?>class="active"<?php } ?> data-id="all">
  30. Show all
  31. <?php if ($get_category=="") { ?><div class="active-state"></div><?php } ?>
  32. </a>
  33. <?php
  34.  
  35.  
  36.  
  37. // get all custom taxonomies project-category
  38. $terms = get_terms( array(
  39. 'taxonomy' => 'project-category',
  40. 'hide_empty' => true,
  41. ));
  42.  
  43. //echo print_r($terms, true);
  44. foreach ($terms as $term) {
  45. $class = ($get_category == $term->slug) ? 'active' : '';
  46. $active_bg = ($get_category == $term->slug) ? '<div class="active-state"></div>' : '';
  47. echo '<a href="?category='.$term->slug.'" class="'.$class.'" data-id="'.$term->term_id.'">'.$term->name.$active_bg .'</a>';
  48. }
  49. ?>
  50. </div>
  51. </div>
  52.  
  53. <?php
  54.  
  55.  
  56.  
  57.  
  58. // get all projecten
  59.  
  60. // Get the current page number
  61. $paged = max(1, get_query_var('paged'));
  62.  
  63. //echo $get_category;
  64. //echo $paged;
  65.  
  66. // Set the number of posts per page
  67. $posts_per_page = 1; // Change this to the desired number of posts per page
  68.  
  69. //echo $get_category;
  70. //flush_rewrite_rules();
  71.  
  72. $args = array(
  73. 'suppress_filters' => false,
  74. 'post_type' => 'projects',
  75. 'post_status' => 'publish',
  76. 'posts_per_page' => $posts_per_page,
  77. 'order_by' => 'date',
  78. 'order' => 'DESC',
  79. 'paged' => $paged,
  80.  
  81. );
  82.  
  83.  
  84. // handle search
  85. if ($search!="") {
  86. $args['s'] = $search;
  87. }
  88.  
  89. // handle category filter
  90. if (!empty($get_category)) {
  91. $args['tax_query'] = array(
  92. array(
  93. 'taxonomy' => 'project-category',
  94. 'field' => 'slug',
  95. 'terms' => $get_category,
  96. ),
  97. );
  98. }
  99.  
  100. $project_query = new WP_Query($args);
  101. //echo print_r($project_query, true);
  102. ?>
  103.  
  104. <div id="project-holder" class="row">
  105. <?php
  106. if ($project_query->have_posts()) : while ($project_query->have_posts()) : $project_query->the_post();
  107. $overzicht_tekst = get_field('overzicht_tekst');
  108. $header_image = get_field('header_image');
  109.  
  110. if ($overzicht_tekst == "") {
  111. $overzicht_tekst = get_the_excerpt();
  112. // limit the excerpt to 9 words
  113. $overzicht_tekst = wp_trim_words($overzicht_tekst, 9);
  114. }
  115. ?>
  116. <div class="col col-6">
  117. <a href="<?php the_permalink(); ?>" title="<?php the_title();?>">
  118. <?php
  119. if ($header_image){
  120. echo wp_get_attachment_image($header_image['ID'], 'medium-width-c', false, array('class' => 'fw'));
  121. }else{
  122. echo '<img src="/static/img/project-list-img-min.jpg" alt="Project 1" class="fw">';
  123. }
  124. ?>
  125. </a>
  126. <p class="item-desc">
  127. <?php echo $overzicht_tekst; ?>
  128. </p>
  129. </div>
  130.  
  131. <?php
  132. endwhile;
  133. endif;
  134. ?>
  135.  
  136. <div id="project-pagination" class="pagination col col-12">
  137. <?php
  138. $big = 999999999; // need an unlikely integer
  139.  
  140. echo paginate_links( array(
  141. 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
  142. 'format' => '?paged=%#%',
  143. 'current' => max( 1, get_query_var('paged') ),
  144. 'total' => $project_query->max_num_pages,
  145. 'prev_text' => '« vorige',
  146. 'next_text' => 'volgende »',
  147. ) );
  148. ?>
  149. </div>
  150. </div>
  151.  
  152. <?php
  153.  
  154. get_footer();
  155.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement