Created
November 23, 2011 16:20
-
-
Save marushu/1389104 to your computer and use it in GitHub Desktop.
register_post_type()の引数であるregister_meta_box_cbのコールバック巻数
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 | |
/****************************************************************************/ | |
/* ! ▼register_post_typeのregister_meta_box_cbのコールバックここから | |
参考URL:http://wpxtreme.jp/how-to-use-custom-post-types-in-wordpress-3-0-beta1 | |
http://wpdocs.sourceforge.jp/関数リファレンス/add_meta_box | |
http://ja.forums.wordpress.org/topic/4693?replies=4 | |
*/ | |
/****************************************************************************/ | |
function my_limit_day_meta_box($post){ | |
add_meta_box('my_limit_day_meta', '表示期限', 'my_limit_day_meta_html', 'one_line_comment', 'normal', 'high'); | |
} | |
function my_limit_day_meta_html($post, $box){ | |
$days = get_post_meta($post->ID, 'days', true); | |
//var_dump( $post ); | |
echo wp_nonce_field('my_limit_day_meta', 'my_meta_nonce'); | |
echo '<p style="font-weight: bold; font-size: 1.4em; color: #016701;">この投稿を表示させる日数は、'; | |
echo '<input style="font-weight: bold; font-size: 1.8em; width: 5em; text-align: center;" type="text" name="days" value="' . $days . '" size="10"> 日間です。</p>'; | |
//echo '<p>ココは日にちが入るはずなんだけどなぁ…' . $days . '</p>'; | |
} | |
add_action('save_post', 'my_limit_day_meta_update'); | |
function my_limit_day_meta_update($post_id){ | |
if(!wp_verify_nonce( $_POST['my_meta_nonce'], 'my_limit_day_meta')) | |
return $post_id; | |
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) | |
return $post_id; | |
if('one_line_comment' == $_POST['post_type']){ | |
if(!current_user_can('edit_post', $post_id)) | |
return $post_id; | |
}else{ | |
return $post_id; | |
} | |
$days = $_POST['days']; | |
if ( "" == get_post_meta( $post_id, 'days' )) { | |
add_post_meta( $post_id, 'days', $days, true ) ; | |
} else if ( $days != get_post_meta( $post_id, 'days' )) { | |
update_post_meta( $post_id, 'days', $days ) ; | |
} else if ( "" == $days ) { | |
delete_post_meta( $post_id, 'days' ) ; | |
} | |
} | |
// | |
add_filter('manage_edit-one_line_comment_columns', 'my_limit_day_columns'); | |
function my_limit_day_columns($columns){ | |
$columns = array( | |
'cb' => '<input type="checkbox"/>', | |
'title' => '1行コメントタイトル', | |
'days' => '設定表示期間(日)', | |
'date' => '日付' | |
); | |
return $columns; | |
} | |
// | |
add_action('manage_posts_custom_column', 'my_limit_day_column'); | |
function my_limit_day_column($column){ | |
global $post; | |
if('image' == $column) the_post_thumbnail(array(64, 64), 'class=featured-image'); //あったら出る | |
elseif ("tag" == $column) the_terms(0, 'span'); //あったら出る | |
elseif ("days" == $column) echo get_post_meta($post->ID, 'days', true); //今回はコレが出る | |
} | |
// ▲register_post_typeのregister_meta_box_cbのコールバックここまで | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment