我有一个自定义元框在我的页面管理与5个复选框。如果选中一个或多个复选框,我希望页面上显示某些内容。
我已经在管理员中正确显示并保存了元框复选框,但是我需要在模板文件中放置什么来显示基于是否从管理员选中复选框的内容呢?
例如,如果在admin中选中了Web开发、徽标设计和打印设计,那么我希望页面显示以下内容:
网页开发
标志设计印刷设计add_action( \'add_meta_boxes\', \'add_custom_box\' );
function add_custom_box( $post ) {
add_meta_box(
\'Meta Box\', // ID, should be a string.
\'Services\', // Meta Box Title.
\'services_meta_box\', // Your call back function, this is where your form field will go.
\'page\', // The post type you want this to show up on, can be post, page, or custom post type.
\'normal\', // The placement of your meta box, can be normal or side.
\'core\' // The priority in which this will be displayed.
);
}
function services_meta_box($post) {
wp_nonce_field( \'my_awesome_nonce\', \'awesome_nonce\' );
$checkboxMeta = get_post_meta( $post->ID );
?>
<input type="checkbox" name="ui-ux-design" id="ui-ux-design" value="yes" <?php if ( isset ( $checkboxMeta[\'ui-ux-design\'] ) ) checked( $checkboxMeta[\'ui-ux-design\'][0], \'yes\' ); ?> />UI/UX Design<br />
<input type="checkbox" name="web-development" id="web-development" value="yes" <?php if ( isset ( $checkboxMeta[\'web-development\'] ) ) checked( $checkboxMeta[\'web-development\'][0], \'yes\' ); ?> />Web Development<br />
<input type="checkbox" name="logo-design" id="logo-design" value="yes" <?php if ( isset ( $checkboxMeta[\'logo-design\'] ) ) checked( $checkboxMeta[\'logo-design\'][0], \'yes\' ); ?> />Logo Design<br />
<input type="checkbox" name="branding" id="branding" value="yes" <?php if ( isset ( $checkboxMeta[\'branding\'] ) ) checked( $checkboxMeta[\'branding\'][0], \'yes\' ); ?> />Branding<br />
<input type="checkbox" name="print-design" id="print-design" value="yes" <?php if ( isset ( $checkboxMeta[\'print-design\'] ) ) checked( $checkboxMeta[\'print-design\'][0], \'yes\' ); ?> />Print Design<br />
<?php }
add_action( \'save_post\', \'save_services_checkboxes\' );
function save_services_checkboxes( $post_id ) {
if ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE )
return;
if ( ( isset ( $_POST[\'my_awesome_nonce\'] ) ) && ( ! wp_verify_nonce( $_POST[\'my_awesome_nonce\'], plugin_basename( __FILE__ ) ) ) )
return;
if ( ( isset ( $_POST[\'post_type\'] ) ) && ( \'page\' == $_POST[\'post_type\'] ) ) {
if ( ! current_user_can( \'edit_page\', $post_id ) ) {
return;
}
} else {
if ( ! current_user_can( \'edit_post\', $post_id ) ) {
return;
}
}
//saves ui-ux-design\'s value
if( isset( $_POST[ \'ui-ux-design\' ] ) ) {
update_post_meta( $post_id, \'ui-ux-design\', \'yes\' );
} else {
update_post_meta( $post_id, \'ui-ux-design\', \'no\' );
}
//saves web-development\'s value
if( isset( $_POST[ \'web-development\' ] ) ) {
update_post_meta( $post_id, \'web-development\', \'yes\' );
} else {
update_post_meta( $post_id, \'web-development\', \'no\' );
}
//saves logo-design\'s value
if( isset( $_POST[ \'logo-design\' ] ) ) {
update_post_meta( $post_id, \'logo-design\', \'yes\' );
} else {
update_post_meta( $post_id, \'logo-design\', \'no\' );
}
//saves branding\'s value
if( isset( $_POST[ \'branding\' ] ) ) {
update_post_meta( $post_id, \'branding\', \'yes\' );
} else {
update_post_meta( $post_id, \'branding\', \'no\' );
}
//saves print design\'s value
if( isset( $_POST[ \'print-design\' ] ) ) {
update_post_meta( $post_id, \'print-design\', \'yes\' );
} else {
update_post_meta( $post_id, \'print-design\', \'no\' );
}
}