Skip to content

Instantly share code, notes, and snippets.

@WebEndevSnippets
Created January 19, 2013 16:26
Show Gist options
  • Save WebEndevSnippets/4573491 to your computer and use it in GitHub Desktop.
Save WebEndevSnippets/4573491 to your computer and use it in GitHub Desktop.
Genesis: Add Custom Links for 'Buy At' Section (uses custom fields)
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') . '/&amp;tag=cherylshirema-20', ) );
we_buy_link( array( 'field' => 'we_barnes-url', 'label' => 'Barnes &amp; 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' => ' &#124;',
);
$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