Created
January 19, 2013 16:26
-
-
Save WebEndevSnippets/4573491 to your computer and use it in GitHub Desktop.
Genesis: Add Custom Links for 'Buy At' Section (uses custom fields)
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
add_action( 'genesis_after_post_content', 'shireman_do_buyat_section', 5 ); | |
/** | |
* Add 'BUY AT' Section for Book URLs on Published Books CPT | |
* | |
*/ | |
function shireman_do_buyat_section() { | |
if ( 'we_published-book' == get_post_type() ) { | |
echo '<div id="buy-at">'; | |
echo '<div class="buy-lead-in"><i class="icon-book"></i>BUY AT:'; | |
echo '</div>'; | |
echo '<div class="buy-links">'; | |
we_buy_link( array( 'field' => 'we_amazon-url', 'label' => 'Amazon', 'url' => genesis_get_custom_field('we_amazon-url') . '/&tag=cherylshirema-20', ) ); | |
we_buy_link( array( 'field' => 'we_barnes-url', 'label' => 'Barnes & Noble', ) ); | |
we_buy_link( array( 'field' => 'we_kobo-url', 'label' => 'Kobo', ) ); | |
we_buy_link( array( 'field' => 'we_sony-url', 'label' => 'Sony', ) ); | |
we_buy_link( array( 'field' => 'we_smashwords-url', 'label' => 'Smashwords', 'after' => '', ) ); | |
// Check if ASIN is entered. If so, display Kindle Price | |
if( genesis_get_custom_field('we_amazon-asin-book') != '' ) { | |
$ASIN = genesis_get_custom_field( 'we_amazon-asin-book' ); | |
if ( function_exists(amazon_shortcode) ) echo amazon_shortcode("template=kindle price&asin='$ASIN'"); | |
} | |
// Check if Amazon ISBN-10 is entered. If so, display paperback Price | |
if( genesis_get_custom_field('we_createspace-isbn-10') != '' ) { | |
$ISBN10 = genesis_get_custom_field( 'we_createspace-isbn-10' ); | |
if ( function_exists(amazon_shortcode) ) echo amazon_shortcode("template=amazon paperback price&asin='$ISBN10'"); | |
} | |
echo '</div><!--end .buy-links -->'; | |
echo '</div><!--end #buy-at -->'; | |
} | |
} | |
/** | |
* Outputs Buy Link HTML | |
* | |
* @param array $args Array of output arguments | |
*/ | |
function we_buy_link( $args ) { | |
$defaults = array( | |
'field' => '', | |
'url' => '', | |
'label' => '', | |
'after' => ' |', | |
); | |
$args = wp_parse_args( $args, $defaults ); | |
$url = isset( $args['url'] ) ? esc_url( $args['url'] ) : esc_url( genesis_get_custom_field( $args['field'] ) ); | |
if( genesis_get_custom_field( $args['field'] ) ) { ?> | |
<div class="buy-link"> | |
<a href="<?php echo $url; ?>" target="_blank"><?php _e( $args['label'], 'child' ); ?></a><?php echo $args['after']; ?> | |
</div> | |
<?php } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment