Last active
December 26, 2015 02:09
-
-
Save jamiemitchell/7075888 to your computer and use it in GitHub Desktop.
Display custom metaboxes for art site on archive page. If price field in empty in backend the "Sold" will show.
This file contains hidden or 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 content and add metaboxes | |
------------------------------------------------------------ */ | |
remove_action( 'genesis_entry_content', 'genesis_do_post_content' ); | |
add_action( 'genesis_entry_content', 'custom_gallery_meta' ); | |
function custom_gallery_meta() { | |
global $post; | |
$artwork_title = get_post_meta( $post->ID, '_cmb_artwork_title', true ); | |
$artwork_desc = get_post_meta( $post->ID, '_cmb_artwork_desc', true ); | |
$artwork_dimensions = get_post_meta( $post->ID, '_cmb_artwork_dimensions', true ); | |
$artwork_price = get_post_meta( $post->ID, '_cmb_artwork_price', true ); | |
if(!empty($artwork_title)) echo $artwork_title . '<br />'; | |
if(!empty($artwork_desc)) echo $artwork_desc . '<br />'; | |
if(!empty($artwork_dimensions)) echo $artwork_dimensions . '<br />'; | |
if(!empty($artwork_price)) { | |
echo $artwork_price = money_format( '%(#10n', $artwork_price) . ' <a href="' . get_permalink() .'" title="' . the_title_attribute( 'echo=0' ) . '">Enquire</a>'; | |
} else { | |
echo 'Sold'; | |
} | |
} |
This file contains hidden or 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 | |
/** | |
* Include and setup custom metaboxes and fields. | |
* | |
* @category Gallery | |
* @package Metaboxes | |
* @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later) | |
* @link https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress | |
*/ | |
add_filter( 'cmb_meta_boxes', 'cmb_sample_metaboxes' ); | |
function cmb_sample_metaboxes( array $meta_boxes ) { | |
$prefix = '_cmb_'; | |
$meta_boxes[] = array( | |
'id' => 'test_metabox', | |
'title' => 'Gallery Info', | |
'pages' => array( 'gallery'), | |
'context' => 'normal', | |
'priority' => 'high', | |
'show_names' => true, | |
'fields' => array( | |
array( | |
'name' => 'Artwork Title', | |
'desc' => 'Name or title of the artwork', | |
'id' => $prefix . 'artwork_title', | |
'type' => 'text', | |
), | |
array( | |
'name' => 'Artwork Price', | |
'desc' => 'Price of the artwork. Leave blank if SOLD!', | |
'id' => $prefix . 'artwork_price', | |
'type' => 'text_money', | |
), | |
array( | |
'name' => 'Artwork Description', | |
'desc' => 'Artwork description (Keep this short)', | |
'id' => $prefix . 'artwork_desc', | |
'type' => 'text', | |
), | |
array( | |
'name' => 'Artwork Dimensions', | |
'desc' => 'Artwork dimensions', | |
'id' => $prefix . 'artwork_dimensions', | |
'type' => 'text', | |
), | |
) | |
); | |
return $meta_boxes; | |
} | |
add_action( 'init', 'cmb_initialize_cmb_meta_boxes', 9999 ); | |
function cmb_initialize_cmb_meta_boxes() { | |
if ( ! class_exists( 'cmb_Meta_Box' ) ) | |
require_once 'init.php'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment