-
-
Save wpsmith/4539554 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 | |
remove_action( 'genesis_header', 'genesis_do_header' ); | |
add_action( 'genesis_header', 'shireman_do_custom_header' ); | |
/** | |
* Modify the default header, including the #title-area div, | |
* along with #title and #description. | |
* | |
* Calls the genesis_site_title, and genesis_site_description. | |
* | |
* Adds book thumbnail display. | |
* | |
*/ | |
function shireman_do_custom_header() { | |
echo '<div id="title-area">'; | |
do_action( 'genesis_site_description' ); | |
do_action( 'genesis_site_title' ); | |
echo '<div class="book-area">'; | |
if ( is_home() ) { | |
$args = array( | |
'meta_key' => 'header_order', | |
'orderby' => 'meta_value_num', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'we_book-category', | |
'field' => 'id', | |
'terms' => array( 78 ), | |
) | |
) | |
); | |
} | |
elseif ( is_page( 2023 ) ) { // Kids Books Page | |
$args = array( | |
'orderby' => 'rand', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'we_book-category', | |
'field' => 'id', | |
'terms' => array( 55 ), | |
) | |
) | |
); | |
} | |
elseif ( is_page( 8 ) ) { // Novels Page | |
$args = array( | |
'meta_key' => 'header_order', | |
'orderby' => 'meta_value_num', | |
'order' => 'ASC', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'we_book-category', | |
'field' => 'id', | |
'terms' => array( 54 ), | |
) | |
) | |
); | |
} | |
elseif ( is_page( 2166 ) ) { // Non Fiction Page | |
$args = array( | |
'meta_key' => 'nonfiction_header_order', | |
'orderby' => 'meta_value_num', | |
'order' => 'ASC', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'we_book-category', | |
'field' => 'id', | |
'terms' => array( 79 ), | |
) | |
) | |
); | |
} | |
elseif ( is_page( 2025 ) ) { // Indie Chicks Books Page | |
$args = array( | |
'orderby' => 'rand', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'we_book-category', | |
'field' => 'id', | |
'terms' => array( 56 ), | |
) | |
) | |
); | |
} | |
elseif ( is_archive() || is_page() || is_single() ) { | |
$args = array(); | |
} | |
shireman_books_header_loop( $args ); | |
echo '</div><!-- end .book-area -->'; | |
echo '</div><!-- end #title-area -->'; | |
} | |
function shireman_books_header_loop( $args ) { | |
global $post; | |
$defaults = array( | |
'orderby' => 'rand', | |
'post_type' => 'we_published-book', | |
'posts_per_page' => 9, | |
'post_status' => 'publish', | |
'no_found_rows' => true, // counts posts, remove if pagination required | |
'update_post_term_cache' => false, // grabs terms, remove if terms required (category, tag...) | |
'update_post_meta_cache' => false, // grabs post meta, remove if post meta required | |
); | |
$args = wp_parse_args( $args, $defaults ); | |
if ( false === ( $bookthumbs = get_transient( 'we_books_header_' . $post->ID ) ) ) { | |
$bookthumbs = new WP_Query( $args ); | |
// Set transient for 1 day | |
set_transient( 'we_books_header_' . $post->ID, $bookthumbs, 60*60*24 ); | |
} | |
if ( $bookthumbs->have_posts() ) { | |
echo '<ul>'; | |
while ( $bookthumbs->have_posts() ) : $bookthumbs->the_post(); | |
if( has_post_thumbnail() ) { | |
printf( '<li><a href="%s" title="%s"><span class="roll" ></span>%s</a></li>', get_permalink(), get_the_title(), genesis_get_image( array( 'format' => 'html', 'size' => 'book-small', ) ) ); | |
} | |
endwhile; | |
echo '</ul>'; | |
} | |
wp_reset_query(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment