Created
February 3, 2013 02:56
-
-
Save robneu/4700365 to your computer and use it in GitHub Desktop.
A page template for displaying a single pet custom post type.
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 | |
/** | |
* The custom pets post type single post template | |
*/ | |
/** Remove Default Genesis Sidebar */ | |
add_action( 'get_header', 'pet_init', 20 ); | |
function pet_init() { | |
remove_action('genesis_sidebar', 'ss_do_sidebar'); | |
add_action( 'genesis_sidebar', 'strays_fp_sidebar' ); | |
} | |
/** Function to output my custom sidebar */ | |
function strays_fp_sidebar() { | |
dynamic_sidebar( 'featured-sidebar' ); | |
} | |
/** Make sure GravityForm scripts are enqeued */ | |
add_action( 'get_header', 'strays_adoption_scripts' ); | |
function strays_adoption_scripts() { | |
if ( function_exists( 'gravity_form_enqueue_scripts' ) ) { | |
gravity_form_enqueue_scripts(4, true); | |
} | |
} | |
/** Limit Search to Pets */ | |
function strays_search_limit($form, $search_text, $button_text) { | |
$onfocus = " onfocus=\"if (this.value == '$search_text') {this.value = '';}\""; | |
$onblur = " onblur=\"if (this.value == '') {this.value = '$search_text';}\""; | |
$pets_form = ' | |
<form method="get" action="' . get_option('home') . '/" > | |
<input type="text" value="'. $search_text .'" name="s"'. $onfocus . $onblur .' /> | |
<input type="hidden" name="post_type" value="pets" /> | |
<input type="submit" value="'. $button_text .'" /> | |
</form> | |
'; | |
return $pets_form; | |
} | |
add_filter('genesis_search_form', 'strays_search_limit', 10, 3); | |
/** Remove the post info function */ | |
remove_action( 'genesis_before_post_content', 'genesis_post_info' ); | |
/** Add Featured Image to Posts - the Webonanza style */ | |
add_action( 'genesis_before_post_content', 'strays_do_pet_top' ); | |
function strays_do_pet_top() { ?> | |
<div class="pet-top"> | |
<div class="pet-images"> | |
<?php | |
global $post; | |
if ( has_post_thumbnail() ) { | |
$url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full'); | |
$large_image = strays_image_resize( $url[0], 800, 520 ); | |
$main_image = strays_image_resize( $url[0], 350, 225 ); | |
echo '<a href="' . $large_image['url'] . '" title="' . the_title_attribute('echo=0') . '" >'; | |
echo '<img src="' . $main_image['url'] . '" alt="' . get_the_title() . '" title="' . get_the_title() . '" />'; | |
echo '</a>'; | |
strays_count_images(); | |
} | |
else { | |
echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/default-thumb.png" alt="' . get_the_title() . '" title="' . get_the_title() . '" />'; | |
} | |
?> | |
</div> | |
<div class="pet-info"> | |
<div class="meta"> | |
<?php | |
/** Return the first taxonomy term name */ | |
function strays_tax_terms( $taxonomy, $term ) { | |
global $post; | |
$terms = get_the_terms( $post->ID, $taxonomy ); | |
$term = array_pop($terms); | |
if ( !is_wp_error( $term ) ) { | |
return $term->name; | |
} | |
} | |
/** Get the taxonomy term names for taxonomies in pets-cpt.php */ | |
$pet_breed = strays_tax_terms( 'breeds', $term ); | |
$pet_color = strays_tax_terms( 'colors', $term ); | |
$pet_size = strays_tax_terms( 'pet_sizes', $term ); | |
$pet_born = get_post_meta($post->ID, 'scfs_born', true); | |
$pet_age = strays_tax_terms( 'pet_ages', $term ); | |
$pet_sex = strays_tax_terms( 'pet_sexes', $term ); | |
/** Return the first taxonomy term slug */ | |
function strays_tax_links( $taxonomy, $term ) { | |
global $post; | |
$terms = get_the_terms( $post->ID, $taxonomy ); | |
$term = array_pop($terms); | |
if ( !is_wp_error( $term ) ) { | |
return $term->slug; | |
} | |
} | |
/** Get the taxonomy term slugs for taxonomies in pets-cpt.php */ | |
$link = get_bloginfo( 'url' ); | |
$breed_slug = $link . '/cat-breeds/' . strays_tax_links( 'breeds', $term ) . '/'; | |
$color_slug = $link . '/cat-colors/' . strays_tax_links( 'colors', $term ) . '/'; | |
$size_slug = $link . '/sizes/' . strays_tax_links( 'pet_sizes', $term ) . '/'; | |
$age_slug = $link . '/ages/' . strays_tax_links( 'pet_ages', $term ) . '/'; | |
$sex_slug = $link . '/genders/' . strays_tax_links( 'pet_sexes', $term ) . '/'; | |
?> | |
<span class="breed">Breed - <a href="<?php echo esc_html( $breed_slug ) ?>"><?php echo esc_html( $pet_breed )?></a></span> | |
<span class="color">Color - <a href="<?php echo esc_html( $color_slug ) ?>"><?php echo esc_html( $pet_color ) ?></a></span> | |
<span class="size">Size - <a href="<?php echo esc_html( $size_slug ) ?>"><?php echo esc_html( $pet_size ) ?></a></span> | |
<span class="age">Age - <a href="<?php echo esc_html( $age_slug ) ?>"><?php echo esc_html( $pet_age ) ?></a></span> | |
<span class="sexes">Sex - <a href="<?php echo esc_html( $sex_slug ) ?>"><?php echo esc_html( $pet_sex ) ?></a></span> | |
<span class="born">Born - <?php echo esc_html( $pet_born )?></span> | |
</div> | |
<!-- AddThis Button BEGIN --> | |
<div class="addthis_toolbox addthis_default_style "> | |
<a class="addthis_button_facebook_like" fb:like:layout="box_count"></a> | |
<a class="addthis_button_tweet" tw:count="vertical"></a> | |
<a class="addthis_button_google_plusone" g:plusone:size="tall"></a> | |
<a class="addthis_button_pinterest_pinit" pi:pinit:media="<?php echo $large_image['url'] ?>" pi:pinit:layout="vertical"></a> | |
</div> | |
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=xa-50dd52463e249456"></script> | |
<!-- AddThis Button END --> | |
</div> | |
</div> | |
<?php | |
} | |
/** Remove the post meta function */ | |
remove_action( 'genesis_after_post_content', 'genesis_post_meta' ); | |
/** Add Post Nav to Single Posts */ | |
add_action ('genesis_after_post_content', 'post_navigation'); | |
function post_navigation() { | |
?> | |
<div class="post-nav"> | |
<span class="previous-post fl"> | |
<?php previous_post_link('%link', '« Previous Adoptable Cat'); ?> | |
</span> | |
<span class="next-post fr"> | |
<?php next_post_link('%link', 'Next Adoptable Cat »'); ?> | |
</span> | |
</div> | |
<?php | |
} | |
/** Remove the post meta function */ | |
add_action( 'genesis_after_post_content', 'strays_adoption_form' ); | |
/** Function to output my custom sidebar */ | |
function strays_adoption_form() { | |
if ( function_exists( 'gravity_form' ) ) { | |
gravity_form(4, true, true, false, '', true); | |
} | |
} | |
/** Remove the author box on single posts */ | |
remove_action( 'genesis_after_post', 'genesis_do_author_box_single' ); | |
genesis(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment