Skip to content

Instantly share code, notes, and snippets.

@Dimasmagadan
Created July 17, 2015 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dimasmagadan/cf54ca14b8acd9e4268a to your computer and use it in GitHub Desktop.
Save Dimasmagadan/cf54ca14b8acd9e4268a to your computer and use it in GitHub Desktop.
<?php
/*
Template Name: Customers
*/
// WP_Query arguments
$args = array (
'post_type' => 'customer',
'post_status' => 'publish',
'pagination' => true,
'posts_per_page' => '100',
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) :
// no default values. using these as examples
$taxonomies = array(
'sectors',
);
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => true,
'exclude' => array(),
'exclude_tree' => array(),
'include' => array(),
'number' => '',
'fields' => 'all',
'slug' => '',
'parent' => '',
'hierarchical' => true,
'child_of' => 0,
'get' => '',
'name__like' => '',
'description__like' => '',
'pad_counts' => false,
'offset' => '',
'search' => '',
'cache_domain' => 'core'
);
$terms = get_terms($taxonomies, $args);
?>
<div class="row">
<div class="col-md-12">
<div class="dropdown hot-dropdown" id="result_filter">
<button class="btn dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
Filter by Industry
<i class="fa fa-sort"></i>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation"><a class="filter" role="menuitem" data-filter="all">All</a></li>
<?php foreach($terms as $term): ?>
<li role="presentation"><a class="filter" role="menuitem" data-filter=".industry-<?php echo $term->slug; ?>"><?php echo $term->name; ?></a></li>
<?php endforeach; ?>
</ul>
</div>
</div>
</div>
<hr>
<div class="row" id="results">
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div <?php post_class('col-sm-6 col-md-4 col-md-6 mix'); ?>>
<div class="result fixedthumb">
<header>
<h3><a href="<?php echo get_the_permalink(); ?>"><?php the_title(); ?></a></h3>
</header>
<?php if( has_post_thumbnail() ){ ?>
<div class="thumb-holder">
<a href="<?php echo get_the_permalink(); ?>">
<img src="<?php echo newbox_post_thumbnail(get_the_ID(), 'large' ); ?>" alt="<?php the_title(); ?>" class="result_thumb">
</a>
</div>
<?php } ?>
</div>
</div>
<?php endwhile; wp_reset_postdata(); endif; ?>
</div>
<?php
// This is the template part
<?php
// Here is the post thumbnail function
function newbox_post_thumbnail($id, $size){
if( has_post_thumbnail( $id ) ){
$thumb_id = get_post_thumbnail_id($id);
$thumb_url_array = wp_get_attachment_image_src($thumb_id, $size, true);
$thumb_url = $thumb_url_array[0];
return $thumb_url;
}
return 'http://placehold.it/360x250';
}
<?php
/*
Template Name: Customers
*/
// WP_Query arguments
$args = array (
'post_type' => 'customer',
'post_status' => 'publish',
'pagination' => true,
'posts_per_page' => '100',
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) :
// no default values. using these as examples
$taxonomies = array(
'sectors',
);
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => true,
'exclude' => array(),
'exclude_tree' => array(),
'include' => array(),
'number' => '',
'fields' => 'all',
'slug' => '',
'parent' => '',
'hierarchical' => true,
'child_of' => 0,
'get' => '',
'name__like' => '',
'description__like' => '',
'pad_counts' => false,
'offset' => '',
'search' => '',
'cache_domain' => 'core'
);
$terms = get_terms($taxonomies, $args);
?>
<div class="row">
<div class="col-md-12">
<div class="dropdown hot-dropdown" id="result_filter">
<button class="btn dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
Filter by Industry
<i class="fa fa-sort"></i>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation"><a class="filter" role="menuitem" data-filter="all">All</a></li>
<?php foreach($terms as $term): ?>
<li role="presentation"><a class="filter" role="menuitem" data-filter=".industry-<?php echo $term->slug; ?>"><?php echo $term->name; ?></a></li>
<?php endforeach; ?>
</ul>
</div>
</div>
</div>
<hr>
<div class="row" id="results">
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<?php include(locate_template('templates/result-thumb.php') ); ?>
<?php endwhile; wp_reset_postdata(); endif; ?>
</div>
<?php
// This is the template part
<div <?php post_class('col-sm-6 col-md-4 col-md-6 mix'); ?>>
<div class="result fixedthumb">
<header>
<h3><a href="<?php echo get_the_permalink(); ?>"><?php the_title(); ?></a></h3>
</header>
<?php if( has_post_thumbnail() ){ ?>
<div class="thumb-holder">
<a href="<?php echo get_the_permalink(); ?>">
<img src="<?php echo newbox_post_thumbnail(get_the_ID(), 'large' ); ?>" alt="<?php the_title(); ?>" class="result_thumb">
</a>
</div>
<?php } ?>
</div>
</div>
<?php
// Here is the post thumbnail function
function newbox_post_thumbnail($id, $size){
if( has_post_thumbnail( $id ) ){
$thumb_id = get_post_thumbnail_id($id);
$thumb_url_array = wp_get_attachment_image_src($thumb_id, $size, true);
$thumb_url = $thumb_url_array[0];
return $thumb_url;
}
return 'http://placehold.it/360x250';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment