Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Template name: Projects page
- *
- * This is the most generic template file in a WordPress theme
- * and one of the two required files for a theme (the other being style.css).
- * It is used to display a page when nothing more specific matches a query.
- * E.g., it puts together the home page when no home.php file exists.
- *
- * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
- *
- * @package project-starter
- */
- get_header();
- $get_category = "";
- if (isset($_GET['category'])) {
- // sanitize the tag
- $get_category = sanitize_text_field($_GET['category']);
- }
- ?>
- <div id="title-holder">
- <h1><?php the_title();?></h1>
- </div>
- <div class="row">
- <div id="project-filter-holder" class="filter-holder col col-12 hover-anim-holder">
- <a href="<?php echo (ICL_LANGUAGE_CODE=="en") ? '/projects/':'/projecten/';?>" <?php if ($get_category=="") { ?>class="active"<?php } ?> data-id="all">
- Show all
- <?php if ($get_category=="") { ?><div class="active-state"></div><?php } ?>
- </a>
- <?php
- // get all custom taxonomies project-category
- $terms = get_terms( array(
- 'taxonomy' => 'project-category',
- 'hide_empty' => true,
- ));
- //echo print_r($terms, true);
- foreach ($terms as $term) {
- $class = ($get_category == $term->slug) ? 'active' : '';
- $active_bg = ($get_category == $term->slug) ? '<div class="active-state"></div>' : '';
- echo '<a href="?category='.$term->slug.'" class="'.$class.'" data-id="'.$term->term_id.'">'.$term->name.$active_bg .'</a>';
- }
- ?>
- </div>
- </div>
- <?php
- // get all projecten
- // Get the current page number
- $paged = max(1, get_query_var('paged'));
- //echo $get_category;
- //echo $paged;
- // Set the number of posts per page
- $posts_per_page = 1; // Change this to the desired number of posts per page
- //echo $get_category;
- //flush_rewrite_rules();
- $args = array(
- 'suppress_filters' => false,
- 'post_type' => 'projects',
- 'post_status' => 'publish',
- 'posts_per_page' => $posts_per_page,
- 'order_by' => 'date',
- 'order' => 'DESC',
- 'paged' => $paged,
- );
- // handle search
- if ($search!="") {
- $args['s'] = $search;
- }
- // handle category filter
- if (!empty($get_category)) {
- $args['tax_query'] = array(
- array(
- 'taxonomy' => 'project-category',
- 'field' => 'slug',
- 'terms' => $get_category,
- ),
- );
- }
- $project_query = new WP_Query($args);
- //echo print_r($project_query, true);
- ?>
- <div id="project-holder" class="row">
- <?php
- if ($project_query->have_posts()) : while ($project_query->have_posts()) : $project_query->the_post();
- $overzicht_tekst = get_field('overzicht_tekst');
- $header_image = get_field('header_image');
- if ($overzicht_tekst == "") {
- $overzicht_tekst = get_the_excerpt();
- // limit the excerpt to 9 words
- $overzicht_tekst = wp_trim_words($overzicht_tekst, 9);
- }
- ?>
- <div class="col col-6">
- <a href="<?php the_permalink(); ?>" title="<?php the_title();?>">
- <?php
- if ($header_image){
- echo wp_get_attachment_image($header_image['ID'], 'medium-width-c', false, array('class' => 'fw'));
- }else{
- echo '<img src="/static/img/project-list-img-min.jpg" alt="Project 1" class="fw">';
- }
- ?>
- </a>
- <p class="item-desc">
- <?php echo $overzicht_tekst; ?>
- </p>
- </div>
- <?php
- endwhile;
- endif;
- ?>
- <div id="project-pagination" class="pagination col col-12">
- <?php
- $big = 999999999; // need an unlikely integer
- echo paginate_links( array(
- 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
- 'format' => '?paged=%#%',
- 'current' => max( 1, get_query_var('paged') ),
- 'total' => $project_query->max_num_pages,
- 'prev_text' => '« vorige',
- 'next_text' => 'volgende »',
- ) );
- ?>
- </div>
- </div>
- <?php
- get_footer();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement