I made something for you. I will need it very soon in the future.
- Add this to your functions.php plugin, or in Settings of Themler (CMS Code):
<pre class>/**
* Adds a meta box to the post editing screen
*/
function prfx_featured_meta() {
add_meta_box( 'prfx_meta', __( 'Featured image in Post view', 'prfx-textdomain' ), 'prfx_meta_callback', 'post', 'side', 'high' );
}
add_action( 'add_meta_boxes', 'prfx_featured_meta' );
/**
* Outputs the content of the meta box
*/
function prfx_meta_callback( $post ) {
wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' );
$prfx_stored_meta = get_post_meta( $post->ID );
?>
<p>
<span class="prfx-row-title"><?php _e( 'Show featured image in post view', 'prfx-textdomain' )?></span>
<div class="prfx-row-content">
<label for="featured-checkbox">
<input type="checkbox" name="featured-checkbox" id="featured-checkbox" value="yes" <?php if ( isset ( $prfx_stored_meta['featured-checkbox'] ) ) checked( $prfx_stored_meta['featured-checkbox'][0], 'yes' ); ?> />
<?php _e( 'Featured Item in detailed Post view', 'prfx-textdomain' )?>
</label>
</div>
</p>
<?php
}
/**
* Saves the custom meta input
*/
function prfx_meta_save( $post_id ) {
// Checks save status - overcome autosave, etc.
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'prfx_nonce' ] ) && wp_verify_nonce( $_POST[ 'prfx_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
// Exits script depending on save status
if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
return;
}
// Checks for input and saves - save checked as yes and unchecked at no
if( isset( $_POST[ 'featured-checkbox' ] ) ) {
update_post_meta( $post_id, 'featured-checkbox', 'yes' );
} else {
update_post_meta( $post_id, 'featured-checkbox', 'no' );
}
}
add_action( 'save_post', 'prfx_meta_save' );
<pre class><?php
$featured_image_post = get_post_meta($post->ID, 'featured-checkbox', true);
if( 'yes' == ($featured_image_post) ) { ?>
<!-- Do stuff if there is a value -->
<?php echo theme_get_post_thumbnail(array('imageClass' => ' bd-imagestyles', 'class' => ' bd-postimage')); ?>
<?php } else { ?>
<!-- Do different stuff if there isn't value -->
<?php } ?></pre>
- Go to your CMS block options and under Style - More styles - Image - (and) More options, style image as you need.
- You have one new metabox when adding/editing Posts in backend, right sidebar above.
I made something for you. I will need it very soon in the future.
- Add this to your functions.php plugin, or in Settings of Themler (CMS Code):
<pre class>/**
* Adds a meta box to the post editing screen
*/
function prfx_featured_meta() {
add_meta_box( 'prfx_meta', __( 'Featured image in Post view', 'prfx-textdomain' ), 'prfx_meta_callback', 'post', 'side', 'high' );
}
add_action( 'add_meta_boxes', 'prfx_featured_meta' );
/**
* Outputs the content of the meta box
*/
function prfx_meta_callback( $post ) {
wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' );
$prfx_stored_meta = get_post_meta( $post->ID );
?>
<p>
<span class="prfx-row-title"><?php _e( 'Show featured image in post view', 'prfx-textdomain' )?></span>
<div class="prfx-row-content">
<label for="featured-checkbox">
<input type="checkbox" name="featured-checkbox" id="featured-checkbox" value="yes" <?php if ( isset ( $prfx_stored_meta['featured-checkbox'] ) ) checked( $prfx_stored_meta['featured-checkbox'][0], 'yes' ); ?> />
<?php _e( 'Featured Item in detailed Post view', 'prfx-textdomain' )?>
</label>
</div>
</p>
<?php
}
/**
* Saves the custom meta input
*/
function prfx_meta_save( $post_id ) {
// Checks save status - overcome autosave, etc.
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'prfx_nonce' ] ) && wp_verify_nonce( $_POST[ 'prfx_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
// Exits script depending on save status
if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
return;
}
// Checks for input and saves - save checked as yes and unchecked at no
if( isset( $_POST[ 'featured-checkbox' ] ) ) {
update_post_meta( $post_id, 'featured-checkbox', 'yes' );
} else {
update_post_meta( $post_id, 'featured-checkbox', 'no' );
}
}
add_action( 'save_post', 'prfx_meta_save' );
- Open your Post view template in Themler. Insert CMS Code block at the top of the post content.
- Add this in your CMS code:
<pre class>&lt;?php
$featured_image_post = get_post_meta($post-&gt;ID, 'featured-checkbox', true);
if( 'yes' == ($featured_image_post) ) { ?&gt;
&lt;!-- Do stuff if there is a value --&gt;
&lt;?php echo theme_get_post_thumbnail(array('imageClass' =&gt; ' bd-imagestyles', 'class' =&gt; ' bd-postimage')); ?&gt;
&lt;?php } else { ?&gt;
&lt;!-- Do different stuff if there isn't value --&gt;
&lt;?php } ?&gt;</pre>
- Go to your CMS block options and under Style - More styles - Image - (and) More options, style image as you need.
- You have one new metabox when adding/editing Posts in backend, right sidebar above.