Skip to content

Commit

Permalink
Added option to disable featured image on the single page.
Browse files Browse the repository at this point in the history
  • Loading branch information
dziudek committed Mar 29, 2013
1 parent 64d3035 commit a2246fa
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 15 deletions.
26 changes: 23 additions & 3 deletions MeetGavernWP/gavern/helpers/helpers.features.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,26 @@ function gavern_post_seo_callback($post) {

function gavern_post_params_callback($post) {
$values = get_post_custom( $post->ID );
$value_title = isset( $values['gavern-post-params-title'] ) ? esc_attr( $values['gavern-post-params-title'][0] ) : 'Y';
$value_title = isset( $values['gavern-post-params-title'] ) ? esc_attr( $values['gavern-post-params-title'][0] ) : 'Y';
$value_image = isset( $values['gavern-post-params-image'] ) ? esc_attr( $values['gavern-post-params-image'][0] ) : 'Y';
// nonce
wp_nonce_field( 'gavern-post-params-nonce', 'gavern_meta_box_params_nonce' );
// output
// output for the title option
echo '<p>';
echo '<label for="gavern-post-params-title-value">'.__('Show title:', GKTPLNAME).'</label>';
echo '<select name="gavern-post-params-title-value" id="gavern-post-params-title-value">';
echo '<option value="Y"'.(($value_title == 'Y') ? ' selected="selected"' : '').'>'.__('Enabled', GKTPLNAME).'</option>';
echo '<option value="N"'.(($value_title == 'N') ? ' selected="selected"' : '').'>'.__('Disabled', GKTPLNAME).'</option>';
echo '</select>';
echo '</select>';
echo '</p>';
// output for the featured image option
echo '<p>';
echo '<label for="gavern-post-params-image-value">'.__('Show featured image:', GKTPLNAME).'</label>';
echo '<select name="gavern-post-params-image-value" id="gavern-post-params-image-value">';
echo '<option value="Y"'.(($value_image == 'Y') ? ' selected="selected"' : '').'>'.__('Enabled', GKTPLNAME).'</option>';
echo '<option value="N"'.(($value_image == 'N') ? ' selected="selected"' : '').'>'.__('Disabled', GKTPLNAME).'</option>';
echo '</select>';
echo '</p>';
}

function gavern_metaboxes_save( $post_id ) {
Expand Down Expand Up @@ -122,6 +133,15 @@ function gavern_metaboxes_save( $post_id ) {
// update post meta
update_post_meta( $post_id, 'gavern-post-params-title', esc_attr( $_POST['gavern-post-params-title-value'] ) );
}
//
if( isset( $_POST['gavern-post-params-image-value'] ) ) {
// check the nonce
if( !isset( $_POST['gavern_meta_box_params_nonce'] ) || !wp_verify_nonce( $_POST['gavern_meta_box_params_nonce'], 'gavern-post-params-nonce' ) ) {
return;
}
// update post meta
update_post_meta( $post_id, 'gavern-post-params-image', esc_attr( $_POST['gavern-post-params-image-value'] ) );
}
}


Expand Down
46 changes: 34 additions & 12 deletions MeetGavernWP/layouts/content.post.featured.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,43 @@

global $tpl;

?>
$params = get_post_custom();
$params_image = isset($params['gavern-post-params-image']) ? esc_attr( $params['gavern-post-params-image'][0] ) : 'Y';

<?php
// if there is a Featured Video
if(get_post_meta(get_the_ID(), "_gavern-featured-video", true) != '') :
?>

<?php echo get_post_meta(get_the_ID(), "_gavern-featured-video", true); ?>

<?php elseif(has_post_thumbnail()) : ?>
<figure class="featured-image">
<?php the_post_thumbnail(); ?>
<?php if(is_single() && $params_image == 'Y') : ?>
<?php
// if there is a Featured Video
if(get_post_meta(get_the_ID(), "_gavern-featured-video", true) != '') :
?>

<?php echo get_post_meta(get_the_ID(), "_gavern-featured-video", true); ?>

<?php elseif(has_post_thumbnail()) : ?>
<figure class="featured-image">
<?php the_post_thumbnail(); ?>

<?php if(is_single()) : ?>
<?php echo gk_post_thumbnail_caption(); ?>
<?php endif; ?>
</figure>
<?php endif; ?>
<?php elseif(!is_single()) : ?>
<?php
// if there is a Featured Video
if(get_post_meta(get_the_ID(), "_gavern-featured-video", true) != '') :
?>

<?php echo get_post_meta(get_the_ID(), "_gavern-featured-video", true); ?>

<?php if(is_single()) : ?>
<?php echo gk_post_thumbnail_caption(); ?>
<?php elseif(has_post_thumbnail()) : ?>
<figure class="featured-image">
<?php the_post_thumbnail(); ?>

<?php if(is_single()) : ?>
<?php echo gk_post_thumbnail_caption(); ?>
<?php endif; ?>
</figure>
<?php endif; ?>
</figure>
<?php endif; ?>

0 comments on commit a2246fa

Please sign in to comment.