从自定义主题选项页面调用字段并在前端显示其内容时遇到问题。这是我用来在后端显示自定义主题选项的代码
add_action( \'admin_init\', \'theme_options_init\' );
add_action( \'admin_menu\', \'theme_options_add_page\' );
/** Init plugin options to white list our options **/
function theme_options_init(){
register_setting( \'options\', \'website_options\', \'theme_options_validate\' );
}
/** Load up the menu page **/
function theme_options_add_page() {
add_theme_page( __( \'Blurb Options\', \'websiteBlurbs\' ), __( \'Blurb Options\', \'websiteBlurbs\' ), \'edit_theme_options\', \'theme_options\', \'theme_options_do_page\' );
}
/** Create the options page **/
function theme_options_do_page() {
if ( ! isset( $_REQUEST[\'settings-updated\'] ) )
$_REQUEST[\'settings-updated\'] = false;
?>
<div class="wrap">
<?php screen_icon(); echo "<h2>" . get_current_theme() . __( \' Page Settings\', \'websiteBlurbs\' ) . "</h2>"; ?>
<?php if ( false !== $_REQUEST[\'settings-updated\'] ) : ?>
<div class="updated fade"><p><strong><?php _e( \'Options saved\', \'websiteBlurbs\' ); ?></strong></p></div>
<?php endif; ?>
<form method="post" action="options.php">
<?php settings_fields( \'options\' ); ?>
<?php $options = get_option( \'website_options\' ); ?>
<table class="form-table">
<td><h2>About Page</h2></td>
<?php /* ABOUT */ ?>
<tr valign="top"><th scope="row"><?php _e( \'Title Blurb\', \'aboutBlurb\' ); ?></th>
<td>
<input id="website_options[about]" class="regular-text" type="text" name="website_options[about]" value="<?php esc_attr_e( $options[\'about\'] ); ?>" style="width:50%; padding:1em;" />
<label class="description" for="website_options[about]"></label>
</td>
</tr>
<td><h2>Our Team</h2></td>
<?php /* PROPERTY */ ?>
<tr valign="top"><th scope="row"><?php _e( \'Title Blurb\', \'teamBlurb\' ); ?></th>
<td>
<input id="website_options[team]" class="regular-text" type="text" name="website_options[team]" value="<?php esc_attr_e( $options[\'team\'] ); ?>" style="width:50%; padding:1em;" />
<label class="description" for="website_options[team]"></label>
</td>
</tr>
<td><h2>Property Page</h2></td>
<?php /* PROPERTY */ ?>
<tr valign="top"><th scope="row"><?php _e( \'Title Blurb\', \'propertyBlurb\' ); ?></th>
<td>
<input id="website_options[property]" class="regular-text" type="text" name="website_options[property]" value="<?php esc_attr_e( $options[\'property\'] ); ?>" style="width:50%; padding:1em;" />
<label class="description" for="website_options[property]"></label>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e( \'Save Options\', \'websiteBlurbs\' ); ?>" />
</p>
</form>
</div>
<?php
}
/** Sanitize and validate input. Accepts an array, return a sanitized array. **/
function theme_options_validate( $input ) {
// Say our text option must be safe text with no HTML tags
$input[\'about\'] = wp_filter_nohtml_kses( $input[\'about\'] );
$input[\'property\'] = wp_filter_nohtml_kses( $input[\'property\'] );
$input[\'team\'] = wp_filter_nohtml_kses( $input[\'team\'] );
return $input;
}
我知道如何使用echo get\\u post\\u meta($post->ID,“customfieldname”,true),从自定义post类型调用字段;但是,当我尝试使用此函数调用字段aboutBlurb时,我无法从字段中生成要在前端显示的内容。我没有收到任何错误或无法显示的原因。
要使这项工作正常运行,我缺少什么?