Created
June 28, 2016 20:24
-
-
Save anonymous/3f7242ffda6e6c92f8ce6e115342edee to your computer and use it in GitHub Desktop.
This file contains 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 | |
/* START THE ENGINE ------------------------------------------------------------ */ | |
require_once( get_template_directory() . '/lib/init.php' ); | |
require_once( get_stylesheet_directory() . '/lib/init.php' ); | |
/* ------- DO NOT EDIT THIS FILE ------------ */ | |
/* ------- IT WILL BE OVERWRITTEN ----------- */ | |
/* ---- IF YOU AUTO-UPDATE THE THEME -------- */ | |
//* Do NOT include the opening php tag | |
add_filter( 'wp_nav_menu_items', 'theme_menu_extras', 10, 2 ); | |
/** | |
* Filter menu items, appending either a search form or today's date. | |
* | |
* @param string $menu HTML string of list items. | |
* @param stdClass $args Menu arguments. | |
* | |
* @return string Amended HTML string of list items. | |
*/ | |
function theme_menu_extras( $menu, $args ) { | |
//* Change 'primary' to 'secondary' to add extras to the secondary navigation menu | |
if ( 'primary' !== $args->theme_location ) | |
return $menu; | |
ob_start(); | |
get_search_form(); | |
$search = ob_get_clean(); | |
$menu .= '<li class="right search">' . $search . '</li>'; | |
//* Uncomment this block to add the date to the navigation menu | |
/* | |
$menu .= '<li class="right date">' . date_i18n( get_option( 'date_format' ) ) . '</li>'; | |
*/ | |
return $menu; | |
} | |
/** Adding custom Favicon */ | |
add_filter( 'genesis_pre_load_favicon', 'custom_favicon' ); | |
function custom_favicon( $favicon_url ) { | |
return 'http://genewhitehead.com/gwwp-suitcase/uploads/favicon.ico'; | |
} | |
//* Enqueue scripts | |
add_action( 'wp_enqueue_scripts', 'sk_enqueue_scripts' ); | |
function sk_enqueue_scripts() { | |
if ( is_home() ) { | |
wp_enqueue_script( 'equalheights', get_bloginfo( 'stylesheet_directory' ) . '/js/jquery.equalheights.min.js', array( 'jquery' ), '', true ); | |
wp_enqueue_script( 'equalheights-init', get_stylesheet_directory_uri() . '/js/equalheights-init.js', array( 'equalheights' ), '1.0.0', true ); | |
} | |
} | |
genesis_register_sidebar( array( | |
'id' => 'pagewidget', | |
'name' => __( 'Page Widget', 'nabm' ), | |
'description' => __( 'This is the widget area for a specific page.', 'nabm' ), | |
) ); | |
//* Add the page widget in the content - HTML5 | |
add_action( 'genesis_entry_header', 'nabm_add_page_content' ); | |
function nabm_add_page_content() { | |
if ( is_page(array(2)) ) | |
genesis_widget_area ('pagewidget', array( | |
'before' => '<div class="pagewidget"><div class="wrap">', | |
'after' => '</div></div>', | |
) ); | |
} | |
genesis_register_sidebar( array( | |
'id' => 'aftercontentpagewidget', | |
'name' => __( 'Page Widget', 'nabmafter' ), | |
'description' => __( 'This is the widget area for a specific page.', 'nabmafter' ), | |
) ); | |
//* Add the page widget in the content - HTML5 | |
add_action( 'genesis_entry_footer', 'nabmafter_add_page_content' ); | |
function nabmafter_add_page_content() { | |
if ( is_page(array(910)) ) | |
genesis_widget_area ('aftercontentpagewidget', array( | |
'before' => '<div class="aftercontentpagewidget"><div class="wrap">', | |
'after' => '</div></div>', | |
) ); | |
} | |
genesis_register_sidebar( array( | |
'id' => 'pagewidget', | |
'name' => __( 'Page Widget', 'nabmsubscribe' ), | |
'description' => __( 'This is the widget area for a specific page.', 'nabmsubscribe' ), | |
) ); | |
//* Add the page widget in the content - HTML5 | |
add_action( 'genesis_entry_footer', 'nabmsubscribe_add_page_content' ); | |
function nabmsubscribe_add_page_content() { | |
if ( is_page(array(189, 1341)) ) | |
genesis_widget_area ('pagewidget', array( | |
'before' => '<div class="pagewidget"><div class="wrap">', | |
'after' => '</div></div>', | |
) ); | |
} | |
/* Code to Display Featured Image on top of the post */ | |
add_action( 'genesis_before_entry', 'featured_post_image', 8 ); | |
function featured_post_image() { | |
if ( ! is_singular( 'post' ) ) return; | |
the_post_thumbnail('post-image'); | |
} | |
/** | |
* Grid Loop Pagination | |
* Returns false if not grid loop. | |
* Returns an array describing pagination if is grid loop | |
* | |
* @author Bill Erickson | |
* @link http://www.billerickson.net/a-better-and-easier-grid-loop/ | |
* | |
* @param object $query | |
* @return bool is grid loop (true) or not (false) | |
*/ | |
function be_grid_loop_pagination( $query = false ) { | |
// If no query is specified, grab the main query | |
global $wp_query; | |
if( !isset( $query ) || empty( $query ) || !is_object( $query ) ) | |
$query = $wp_query; | |
// Sections of site that should use grid loop | |
if( ! ( $query->is_home() || $query->is_archive() ) ) | |
return false; | |
// Specify pagination | |
return array( | |
'features_on_front' => 2, | |
'teasers_on_front' => 6, | |
'features_inside' => 10, | |
'teasers_inside' => 0, | |
); | |
} | |
/** | |
* Grid Loop Query Arguments | |
* | |
* @author Bill Erickson | |
* @link http://www.billerickson.net/a-better-and-easier-grid-loop/ | |
* | |
* @param object $query | |
* @return null | |
*/ | |
function be_grid_loop_query_args( $query ) { | |
$grid_args = be_grid_loop_pagination( $query ); | |
if( $query->is_main_query() && !is_admin() && $grid_args ) { | |
// First Page | |
$page = $query->query_vars['paged']; | |
if( ! $page ) { | |
$query->set( 'posts_per_page', ( $grid_args['features_on_front'] + $grid_args['teasers_on_front'] ) ); | |
// Other Pages | |
} else { | |
$query->set( 'posts_per_page', ( $grid_args['features_inside'] + $grid_args['teasers_inside'] ) ); | |
$query->set( 'offset', ( $grid_args['features_on_front'] + $grid_args['teasers_on_front'] ) + ( $grid_args['features_inside'] + $grid_args['teasers_inside'] ) * ( $page - 2 ) ); | |
// Offset is posts on first page + posts on internal pages * ( current page - 2 ) | |
} | |
} | |
} | |
add_action( 'pre_get_posts', 'be_grid_loop_query_args' ); | |
/** | |
* Grid Loop Post Classes | |
* | |
* @author Bill Erickson | |
* @link http://www.billerickson.net/a-better-and-easier-grid-loop/ | |
* | |
* @param array $classes | |
* @return array $classes | |
*/ | |
function be_grid_loop_post_classes( $classes ) { | |
global $wp_query; | |
$grid_args = be_grid_loop_pagination(); | |
if( ! $grid_args || ! $wp_query->is_main_query() ) | |
return $classes; | |
// First Page Classes | |
if( ! $wp_query->query_vars['paged'] ) { | |
// Features | |
if( $wp_query->current_post < $grid_args['features_on_front'] ) { | |
$classes[] = 'feature'; | |
// Teasers | |
} else { | |
$classes[] = 'one-half'; | |
if( 0 == ( $wp_query->current_post - $grid_args['features_on_front'] ) || 0 == ( $wp_query->current_post - $grid_args['features_on_front'] ) % 2 ) | |
$classes[] = 'first'; | |
} | |
// Inner Pages | |
} else { | |
// Features | |
if( $wp_query->current_post < $grid_args['features_inside'] ) { | |
$classes[] = 'feature'; | |
// Teasers | |
} else { | |
$classes[] = 'one-half'; | |
if( 0 == ( $wp_query->current_post - $grid_args['features_inside'] ) || 0 == ( $wp_query->current_post - $grid_args['features_inside'] ) % 2 ) | |
$classes[] = 'first'; | |
} | |
} | |
return $classes; | |
} | |
add_filter( 'post_class', 'be_grid_loop_post_classes' ); | |
/** | |
* Grid Image Sizes | |
* | |
*/ | |
function be_grid_image_sizes() { | |
add_image_size( 'be_grid', 175, 120, true ); | |
add_image_size( 'be_feature', 570, 333, true ); | |
} | |
add_action( 'genesis_setup', 'be_grid_image_sizes', 20 ); | |
/** | |
* Grid Loop Featured Image | |
* | |
* @param string image size | |
* @return string | |
*/ | |
function be_grid_loop_image( $image_size ) { | |
global $wp_query; | |
$grid_args = be_grid_loop_pagination(); | |
if( ! $grid_args ) | |
return $image_size; | |
// Feature | |
if( ( ! $wp_query->query_vars['paged'] && $wp_query->current_post < $grid_args['features_on_front'] ) || ( $wp_query->query_vars['paged'] && $wp_query->current_post < $grid_args['features_inside'] ) ) | |
$image_size = 'be_feature'; | |
if( ( ! $wp_query->query_vars['paged'] && $wp_query->current_post > ( $grid_args['features_on_front'] - 2 ) ) || ( $wp_query->query_vars['paged'] && $wp_query->current_post > ( $grid_args['features_inside'] - 1 ) ) ) | |
$image_size = 'be_grid'; | |
return $image_size; | |
} | |
add_filter( 'genesis_pre_get_option_image_size', 'be_grid_loop_image' ); | |
/** | |
* Fix Posts Nav | |
* | |
* The posts navigation uses the current posts-per-page to | |
* calculate how many pages there are. If your homepage | |
* displays a different number than inner pages, there | |
* will be more pages listed on the homepage. This fixes it. | |
* | |
*/ | |
function be_fix_posts_nav() { | |
if( get_query_var( 'paged' ) ) | |
return; | |
global $wp_query; | |
$grid_args = be_grid_loop_pagination(); | |
if( ! $grid_args ) | |
return; | |
$max = ceil ( ( $wp_query->found_posts - $grid_args['features_on_front'] - $grid_args['teasers_on_front'] ) / ( $grid_args['features_inside'] + $grid_args['teasers_inside'] ) ) + 1; | |
$wp_query->max_num_pages = $max; | |
} | |
add_filter( 'genesis_after_endwhile', 'be_fix_posts_nav', 5 ); | |
// Load Font Awesome | |
add_action( 'wp_enqueue_scripts', 'enqueue_font_awesome' ); | |
function enqueue_font_awesome() { | |
wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment