Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function blog_post_fields_meta_box() {
- add_meta_box(
- 'blog_fields_meta_box', // $id
- 'Blog Settings', // $title
- 'show_blog_fields_meta_box', // $callback
- 'page', // $screen
- 'normal', // $context
- '55' // $priority
- );
- }
- add_action( 'add_meta_boxes', 'blog_post_fields_meta_box' );
- function show_blog_fields_meta_box() {
- global $post;
- $meta = get_post_meta( $post->ID, 'your_fields', true ); ?>
- <input type="hidden" name="your_meta_box_nonce" value="<?php echo wp_create_nonce( basename(__FILE__) ); ?>">
- <p>
- <label for="your_fields[blog_format]">Blog Style/Format : </label>
- <select name="your_fields[blog_format]" id="your_fields[blog_format]">
- <option value="blog-default" <?php selected( @$meta['blog_format'], 'blog-default' ); ?>>Default</option>
- <option value="blog-title-top" <?php selected( @$meta['blog_format'], 'blog-title-top' ); ?>>Title Top</option>
- <option value="blog-image-left" <?php selected( @$meta['blog_format'], 'blog-image-left' ); ?>>Image Left</option>
- <option value="blog-gird-with-featured-post" <?php selected( @$meta['blog_format'], 'blog-gird-with-featured-post' ); ?>>Gird With Featured Post</option>
- </select>
- </p>
- <p>
- <label for="your_fields[select]">Post Format : </label>
- <select name="your_fields[select]" id="your_fields[select]">
- <option value="list-view" <?php selected( @$meta['select'], 'list-view' ); ?>>List</option>
- <option value="grid-view" <?php selected( @$meta['select'], 'grid-view' ); ?>>Grid</option>
- </select>
- </p>
- <p>
- <label for="your_fields[show_thumbnail]">Enable Thumbnail :
- <input type="checkbox" name="your_fields[show_thumbnail]" value="checkbox" <?php if ( @$meta['show_thumbnail'] === 'checkbox' ) echo 'checked'; ?>>
- </label>
- </p>
- <p>
- <label for="your_fields[show_category]">Show Category :
- <input type="checkbox" name="your_fields[show_category]" value="checkbox" <?php if ( @$meta['show_category'] === 'checkbox' ) echo 'checked'; ?>>
- </label>
- </p>
- <p>
- <label for="your_fields[show_heading]">Enable Heading :
- <input type="checkbox" name="your_fields[show_heading]" value="checkbox" <?php if ( @$meta['show_heading'] === 'checkbox' ) echo 'checked'; ?>>
- </label>
- </p>
- <p>
- <label for="your_fields[show_content]">Show Post Content :
- <input id="show-post-content" type="checkbox" name="your_fields[show_content]" value="checkbox" <?php if ( @$meta['show_content'] === 'checkbox' ) echo 'checked'; ?>>
- </label>
- <span>-----></span>
- <label for="your_fields[excerpt_length]">Excerpt Length :
- <input type="number" name="your_fields[excerpt_length]" id="your_fields[excerpt_length]" value="<?php echo @$meta['excerpt_length']; ?>">
- </label>
- </p>
- <p>
- <label for="your_fields[show_read_more]">Show Read More Button :
- <input type="checkbox" name="your_fields[show_read_more]" value="checkbox" <?php if ( @$meta['show_read_more'] === 'checkbox' ) echo 'checked'; ?>>
- </label>
- <span>-----></span>
- <label for="your_fields[read_more_text]">Read More Text :
- <input type="text" name="your_fields[read_more_text]" id="your_fields[read_more_text]" value="<?php echo @@$meta['read_more_text']; ?>">
- </label>
- </p>
- <p>
- <label for="your_fields[show_date]">Show Date :
- <input type="checkbox" name="your_fields[show_date]" value="checkbox" <?php if ( @$meta['show_date'] === 'checkbox' ) echo 'checked'; ?>>
- </label>
- <span>-----</span>
- <label for="your_fields[show_author_name]">Show Author Name :
- <input type="checkbox" name="your_fields[show_author_name]" value="checkbox" <?php if ( @$meta['show_author_name'] === 'checkbox' ) echo 'checked'; ?>>
- </label>
- </p>
- <p>
- <label for="your_fields[show_total_comments]">Show Comments :
- <input type="checkbox" name="your_fields[show_total_comments]" value="checkbox" <?php if ( @$meta['show_total_comments'] === 'checkbox' ) echo 'checked'; ?>>
- </label>
- </p>
- <p>
- <label for="your_fields[define_category]">Define Category :
- <input type="text" name="your_fields[define_category]" id="your_fields[define_category]" value="<?php echo @@$meta['define_category']; ?>">
- </label>
- </p>
- <?php
- }
- function save_your_fields_meta( $post_id ) {
- // verify nonce
- if ( isset($_POST['your_meta_box_nonce']) && !wp_verify_nonce( $_POST['your_meta_box_nonce'], basename(__FILE__) ) ) {
- return $post_id;
- }
- // check autosave
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
- return $post_id;
- }
- // check permissions
- if ( isset($_POST['post_type']) && 'page' === $_POST['post_type'] ) {
- if ( !current_user_can( 'edit_page', $post_id ) ) {
- return $post_id;
- } elseif ( !current_user_can( 'edit_post', $post_id ) ) {
- return $post_id;
- }
- }
- $old = get_post_meta( $post_id, 'your_fields', true );
- // $new = @$_POST['your_fields'];
- if ( isset($_POST['your_fields']) && $_POST['your_fields'] !== $old ) {
- update_post_meta( $post_id, 'your_fields', $_POST['your_fields'] );
- } elseif ( isset($_POST['your_fields']) && '' === $_POST['your_fields'] && $old ) {
- delete_post_meta( $post_id, 'your_fields', $old );
- }
- }
- add_action( 'save_post', 'save_your_fields_meta' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement