Created
July 6, 2017 01:32
-
-
Save mmjaeger/f7a7e16f3674537be700f108ac095541 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* ThingLogix Pro | |
* Description: Used as page template to show filtered resources using "facetwp" | |
* | |
* Template Name: Page Resource | |
* | |
* @package ThingLogix | |
* @author j-cons | |
* @license GPL-2.0+ | |
* @version 1.0.0 | |
* @link http://j-cons.com | |
* @date 07-04-2017 | |
*/ | |
//* Add body class to head | |
add_filter( 'body_class', 'themeprefix_body_class' ); | |
function themeprefix_body_class( $classes ) { | |
$classes[] = 'page-template-resource'; | |
return $classes; | |
} | |
//* Force full width content layout | |
add_filter( 'genesis_site_layout', '__genesis_return_full_width_content' ); | |
//* Add page title | |
//add_action( 'genesis_before_loop', 'ct_add_page_title' ); | |
function ct_add_page_title() { | |
printf( | |
'<div class="archive-description"> | |
<h1 class="archive-title">%s</h1> | |
%s | |
</div>', | |
get_the_title(), ct_category_name_by_query_var() ); | |
} | |
//* Add facets (filter dropdowns) | |
add_action('genesis_after_header', 'themeprefix_add_facets'); | |
function themeprefix_add_facets() { ?> | |
<div class="facet-container"> | |
<div class="wrap"> | |
<div class="facet-inner"> | |
<?php | |
printf( '<div class="facet-item"><h5>Filter by Solution</h5>%s</div>', facetwp_display( 'facet', 'resource_solutions' ) ); | |
printf( '<div class="facet-item"><h5>Filter by Service</h5>%s</div>', facetwp_display( 'facet', 'resource_services' ) ); | |
printf( '<div class="facet-item"><h5>Filter by Type</h5>%s</div>', facetwp_display( 'facet', 'resource_types' ) ); | |
echo '<div class="facet-item flex-end"><button onclick="FWP.reset()">Reset</button></div>'; | |
//echo facetwp_display( 'sort', true ); | |
?> | |
</div><!-- /.facet-inner --> | |
<?php | |
//printf( '<div class="facet-selections">%s</div>', facetwp_display( 'selections', true ) ); | |
?> | |
</div><!-- /.warp --> | |
</div><!-- /.facet-container --> | |
<?php | |
} | |
//* Add facetwp class to content | |
add_filter( 'genesis_attr_content', 'themeprefix_attr_content' ); | |
function themeprefix_attr_content( $atts ) { | |
$atts[ 'class' ] .= ' facetwp-template'; | |
return $atts; | |
} | |
//* Customize header entry meta | |
add_filter( 'genesis_post_info', 'themeprefix_post_info_filter' ); | |
function themeprefix_post_info_filter( $post_info ) { | |
$post_info = '[post_date] [post_edit]'; | |
return $post_info; | |
} | |
//* Customize footer entry meta | |
//add_filter( 'genesis_post_meta', 'themeprefix_post_meta' ); | |
function themeprefix_post_meta() { | |
$terms = get_terms(); | |
$post_meta = '[post_terms taxonomy="resource_category" before="" sep=""]'; | |
return $post_meta; | |
} | |
add_action( 'genesis_entry_header', 'thx_add_archive_entry_cover', 3 ); | |
function thx_add_archive_entry_cover() { | |
global $post; | |
//echo '<pre>'; | |
//print_r($post); | |
//echo '</pre>'; | |
//$type = get_post_meta($post->ID, 'r_type', true ); | |
$vid = has_term( 'videos', 'resource_category', $post->ID ); | |
$pid = $vid ? 2340 : 2339; // attachment id for cover pic | |
$url = $vid ? get_post_meta($post->ID, 'r_vid', true ) : wp_get_attachment_url( get_post_meta($post->ID, 'r_doc', true ) ); | |
printf('<div class="entry-cover"><a href="%s" title="" target="_blank">%s</a></div>', $url, wp_get_attachment_image( $pid, 'medium' ) ); | |
} | |
//* Move Post Title and Post Info from inside Entry Header to Entry Content on Posts page | |
add_action( 'genesis_before_entry', 'themeprefix_reposition_entry_header' ); | |
function themeprefix_reposition_entry_header() { | |
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 ); | |
remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); | |
remove_action( 'genesis_entry_header', 'genesis_post_info', 8 ); | |
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 ); | |
add_action( 'genesis_entry_content', 'genesis_do_post_title', 9 ); | |
add_action( 'genesis_entry_content', 'themeprefix_open_meta_wrap', 9 ); | |
add_action( 'genesis_entry_content', 'genesis_post_info', 9 ); | |
add_action( 'genesis_entry_content', 'themeprefix_add_post_meta', 9); | |
add_action( 'genesis_entry_content', 'themeprefix_close_meta_wrap', 9 ); | |
} | |
//add_action('genesis_entry_content', 'themeprefix_add_post_meta', 10); | |
function themeprefix_add_post_meta() { | |
$pid = $post->ID; | |
$terms = get_the_terms( $pid, 'resource_category' ); | |
$count = count( $terms ); | |
if ( $count > 0 ) { | |
$arr = []; | |
foreach($terms as $term) { | |
//echo 'term: ' . $term->name; | |
$arr[] = sprintf('<span class="entry-term">%s</span>', $term->name); | |
} | |
printf( '<p class="entry-meta"><span class="entry-terms">%s</span></p>', implode('', $arr)); | |
} | |
} | |
//add_action( 'genesis_entry_header', 'themeprefix_open_entry_wrap', 4 ); | |
function themeprefix_open_meta_wrap() { | |
echo '<div class="entry-meta-wrap">'; | |
} | |
//add_action( 'genesis_entry_content', 'themeprefix_close_entry_wrap', 15 ); | |
function themeprefix_close_meta_wrap() { | |
echo '</div>'; | |
} | |
add_action( 'genesis_entry_content', 'themeprefix_entry_content' ); | |
function themeprefix_entry_content() { | |
global $post; | |
/*$pid = $post->ID; | |
$terms = get_the_terms( $pid, 'resource_category' ); | |
$count = count( $terms ); | |
if ( $count > 0 ) { | |
$arr = []; | |
foreach($terms as $term) { | |
//echo 'term: ' . $term->name; | |
$arr[] = sprintf('<span class="entry-term">%s</span>', $term->name); | |
} | |
printf( '<p class="entry-meta"><span class="entry-terms">%s</span></p>', implode('', $arr)); | |
}*/ | |
$txt = get_post_meta( $post->ID, 'r_text', true ); | |
if ( ! empty ( $txt ) ) | |
echo wpautop( $txt ); | |
} | |
//* Do loop | |
remove_action( 'genesis_loop', 'genesis_do_loop' ); | |
add_action( 'genesis_loop', 'themeprefix_do_custom_loop' ); | |
function themeprefix_do_custom_loop() { | |
//global $wp_query, $query_args, $paged; | |
global $query_args; | |
$doctype = get_query_var( 'doctype' ); | |
//$paged = get_query_var( 'fwp_paged' ) ? get_query_var( 'fwp_paged' ) : 1; | |
// Get service taxonomies | |
$terms = get_terms( 'resource_service', array( 'hide_empty' => false ) ); | |
$terms_service = array(); | |
foreach( $terms as $term ) { | |
$terms_service[] = $term->slug; | |
} | |
// Get solution taxonomies | |
$terms = get_terms( 'resource_solution', array( 'hide_empty' => false ) ); | |
$terms_solution = array(); | |
foreach( $terms as $term ) { | |
$terms_solution[] = $term->slug; | |
} | |
$args = array ( | |
'post_type' => 'resource', | |
'post_status' => 'publish', | |
'ignore_sticky_posts' => true, | |
'orderby' => 'date', | |
'order' => 'DESC', | |
'posts_per_page' => 10, | |
//'paged' => $paged, | |
'facetwp' => true | |
); | |
if ( 'video' == $doctype ) { | |
$args[ 'tax_query' ] = array( | |
array( | |
'taxonomy' => 'resource_category', | |
'field' => 'slug', | |
'terms' => 'videos' | |
) | |
); | |
} elseif ( 'doc' == $doctype ){ | |
$args[ 'tax_query' ] = array( | |
'relation' => 'AND', | |
array( | |
'taxonomy' => 'resource_service', | |
'field' => 'slug', | |
'terms' => $terms_service, | |
'operator' => 'OR' | |
), | |
array( | |
'taxonomy' => 'resource_solution', | |
'field' => 'slug', | |
'terms' => $terms_solution, | |
'operator' => 'OR' | |
), | |
array( | |
'taxonomy' => 'resource_category', | |
'field' => 'slug', | |
'terms' => 'videos', | |
'operator' => 'NOT IN' | |
), | |
); | |
} | |
genesis_custom_loop( wp_parse_args( $query_args, $args ) ); | |
} | |
//* Remove the entry footer markup (requires HTML5 theme support) | |
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 ); | |
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 ); | |
//* Remove the entry meta in the entry footer (requires HTML5 theme support) | |
remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); | |
/** | |
* Replace Genesis' Pagination with FacetWP's. | |
*/ | |
add_action( 'loop_end', 'themeprefix_replace_genesis_pagination' ); | |
function themeprefix_replace_genesis_pagination() { | |
//if ( ! ( is_home() || is_archive() || is_search() ) ) { | |
// return; | |
//} | |
remove_action( 'genesis_after_endwhile', 'genesis_posts_nav' ); | |
add_action( 'genesis_after_endwhile', 'themeprefix_posts_nav' ); | |
} | |
add_action( 'genesis_after_endwhile', 'themeprefix_posts_nav' ); | |
function themeprefix_posts_nav() { | |
if ( ! function_exists( 'facetwp_display' ) ) | |
return; | |
// Display facetwp pagination | |
echo facetwp_display( 'pager' ); | |
} | |
// Style pagination to look like Genesis pagination | |
// @author Matt Gibbs | |
// https://gist.github.com/mgibbs189/69176ef41fa4e26d1419 | |
add_filter( 'facetwp_pager_html', 'themeprefix_facetwp_pager', 10, 2 ); | |
function themeprefix_facetwp_pager( $output, $params ) { | |
$output = '<div class="archive-pagination pagination"><ul>'; | |
$page = (int) $params['page']; | |
$total_pages = (int) $params['total_pages']; | |
// Only show pagination when > 1 page | |
if ( 1 < $total_pages ) { | |
if ( 1 < $page ) { | |
$output .= '<li><a class="facetwp-page" data-page="' . ( $page - 1 ) . '">« Previous Page</a></li>'; | |
} | |
if ( 3 < $page ) { | |
$output .= '<li><a class="facetwp-page first-page" data-page="1">1</a></li>'; | |
$output .= ' <span class="dots">…</span> '; | |
} | |
for ( $i = 2; $i > 0; $i-- ) { | |
if ( 0 < ( $page - $i ) ) { | |
$output .= '<li><a class="facetwp-page" data-page="' . ($page - $i) . '">' . ($page - $i) . '</a></li>'; | |
} | |
} | |
// Current page | |
$output .= '<li class="active" aria-label="Current page"><a class="facetwp-page active" data-page="' . $page . '">' . $page . '</a></li>'; | |
for ( $i = 1; $i <= 2; $i++ ) { | |
if ( $total_pages >= ( $page + $i ) ) { | |
$output .= '<li><a class="facetwp-page" data-page="' . ($page + $i) . '">' . ($page + $i) . '</a></li>'; | |
} | |
} | |
if ( $total_pages > ( $page + 2 ) ) { | |
$output .= ' <span class="dots">…</span> '; | |
$output .= '<li><a class="facetwp-page last-page" data-page="' . $total_pages . '">' . $total_pages . '</a></li>'; | |
} | |
if ( $page < $total_pages ) { | |
$output .= '<li><a class="facetwp-page" data-page="' . ( $page + 1 ) . '">Next Page »</a></li>'; | |
} | |
} | |
$output .= '</ul></div>'; | |
return $output; | |
} | |
genesis(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment