使用仪表板中的其他菜单管理自定义的posttype函数



我在WordPress中创建了一个为二十七十个的子主题,并创建了一个滑块函数以显示滑块映像,也可以为该函数提供自定义帖子类型。现在,我在仪表板中的滑块设置中创建了一个额外的菜单,并且需要使用该设置来管理滑块。在这种情况下,我需要具有以下

o   Enable slider option (check box)
o   Enable slider only for logged in users (check box)
o   Set a global title for slider block (text field)

我在后端添加,但在前端没有添加条件以显示基于此的幻灯片。

我该怎么做?

您可以使用此代码并更改页面以渲染选项:

<?php
add_action('admin_menu', 'create_menu');
function create_menu() {
    add_options_page(__( 'Plugin Settings', 'textdomain' ),__( 'Plugin Settings', 'textdomain' ), 'administrator', __FILE__, 'settings_page', __FILE__);
    add_action( 'admin_init', 'mysettings' );
}

function mysettings() {
    register_setting( 'settings-group', 'enable_slider' );
    register_setting( 'settings-group', 'enable_slider_loggedin' );
    register_setting( 'settings-group', 'slider_title' );
}
function settings_page() {
?>
<div class="wrap">
    <h2><?php _e('PluginSettings','textdomain'); ?></h2>
    <form method="post" action="options.php">
        <?php settings_fields( 'settings-group' ); ?>
        <?php do_settings_sections( 'settings-group' ); ?>
        <table class="form-table">
            <tr valign="top">
                <th scope="row"><?php _e(' Enable slider','textdomain'); ?></th>
                <td>
                    <input name="enable_slider" type="checkbox" value="1" <?php checked( '1', get_option( 'enable_slider' ) ); ?> />
                    <p class="description"></p>
                </td>
            </tr>
            <tr valign="top">
                <th scope="row"><?php _e('Enable slider only for logged in users','textdomain'); ?></th>
                <td>
                    <input name="enable_slider_loggedin" type="checkbox" value="1" <?php checked( '1', get_option( 'enable_slider_loggedin' ) ); ?> />
                    <p class="description"></p>
                </td>
            </tr>
            <tr valign="top">
                <th scope="row"><?php _e('Title For Slider','textdomain'); ?></th>
                <td><input type="text" name="slider_title" value="<?php echo get_option('slider_title'); ?>" /></td>
            </tr>           
        </table>
        <?php submit_button(); ?>
    </form>
</div>
<?php } ?>

使用这样的使用:

if ( get_option ('enable_slider') == 1 ) {
// enable
} else {
//disable
}

最新更新