2015-08-17 153 views
2

我正在使用下面的代碼來創建自定義主題選項。主題選項頁面不出現在Wordpress管理面板上

主題options.php

<?php 
// create custom plugin settings menu 
add_action('admin_menu', 'director_create_menu'); 

function director_create_menu() { 

    //create new submenu 
    add_submenu_page('themes.php', 'Director Theme Options', 'Director Options', 'administrator', __FILE__, 'director_settings_page'); 

    //call register settings function 
    add_action('admin_init', 'director_register_settings'); 
} 

function director_register_settings() { 
    //register our settings 
    register_setting('director-settings-group', 'director_facebook'); 
    register_setting('director-settings-group', 'director_twitter'); 
    register_setting('director-settings-group', 'director_rss'); 
    register_setting('director-settings-group', 'director_logo'); 
    register_setting('director-settings-group', 'director_analytics'); 
} 

function director_settings_page() { 

?> 

<div class="wrap"> 
<h2>Director Theme Settings</h2> 

<form id="landingOptions" method="post" action="options.php"> 
    <?php settings_fields('director-settings-group'); ?> 
    <table class="form-table"> 
     <tr valign="top"> 
     <th scope="row">Logo:</th> 
     <td> 
      <input type="text" name="director_logo" value="<?php print get_option('director_logo'); ?>" /><br/> 
      *Upload using the Media Uploader and paste the URL here. 
     </td> 
     </tr> 
     <tr valign="top"> 
     <th scope="row">Facebook Link:</th> 
     <td> 
      <input type="text" name="director_facebook" value="<?php print get_option('director_facebook'); ?>" /> 
     </td> 
     </tr> 
      <tr valign="top"> 
     <th scope="row">Twitter Link:</th> 
     <td> 
      <input type="text" name="director_twitter" value="<?php print get_option('director_twitter'); ?>" /> 
     </td> 
     </tr> 
     <tr> 
     <th scope="row">Display RSS Icon:</th> 
     <td> 
      <input type="checkbox" name="director_rss" <?php if(get_option('director_rss') == true){ print "checked"; } ?> /> 
     </td> 
     </tr> 
     <tr> 
     <th scope="row">Google Analytics Code:</th> 
     <td> 
      <textarea name="director_analytics"><?php print get_option('director_analytics'); ?></textarea> 
     </td> 
     </tr>  
    </table> 
    <p class="submit"> 
    <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> 
    </p> 

</form> 
</div> 
<?php } ?> 

的functions.php

<?php 
. 
. 
require_once('theme-options.php'); 
. 
. 
?> 

我得到了菜單「董事期權」,你可以在下面的圖片中看到。

enter image description here

但是,當我點擊它的director_settings_page()作用下定義,我不能登陸到設置頁面。

這裏是預期的結果

enter image description here

回答

1

我做到這一點,我用add_theme_page(),而不是add_submenu_page()。試試看看它是否有幫助。也許它會引導你走向正確的方向。

<?php 

add_action('admin_menu', 'director_create_menu'); 
function director_create_menu(){ 
    add_theme_page('Director Theme Options', 'Director Theme Options', 'manage_options', 'director_settings', 'director_settings_page'); 
} 


add_action('admin_init', 'director_register_settings'); 
function director_register_settings(){ 
    //register our settings 
    register_setting('director-settings-group', 'director_facebook'); 
    register_setting('director-settings-group', 'director_twitter'); 
    register_setting('director-settings-group', 'director_rss'); 
    register_setting('director-settings-group', 'director_logo'); 
    register_setting('director-settings-group', 'director_analytics'); 
} 


//Output the settings page 
function director_settings_page(){ 
?> 
    <!-- page stuff here --> 
1

將其替換到您的theme-options.php中。

<?php 
add_action('admin_menu', 'director_create_menu'); 
function director_create_menu(){ 
    add_theme_page('Director Theme Options', 'Director Theme Options', 'manage_options', 'director_settings', 'director_settings_page'); 
} 
add_action('admin_init', 'director_register_settings'); 
function director_register_settings(){ 
    //register our settings 
    register_setting('director-settings-group', 'director_facebook'); 
    register_setting('director-settings-group', 'director_twitter'); 
    register_setting('director-settings-group', 'director_rss'); 
    register_setting('director-settings-group', 'director_logo'); 
    register_setting('director-settings-group', 'director_analytics'); 
} 
//Output the settings page 
function director_settings_page(){ 
?> 
<div class="wrap"> 
<h2>Director Theme Settings</h2> 

<form id="landingOptions" method="post" action="options.php"> 
    <?php settings_fields('director-settings-group'); ?> 
    <table class="form-table"> 
     <tr valign="top"> 
     <th scope="row">Logo:</th> 
     <td> 
      <input type="text" name="director_logo" value="<?php print get_option('director_logo'); ?>" /><br/> 
      *Upload using the Media Uploader and paste the URL here. 
     </td> 
     </tr> 
     <tr valign="top"> 
     <th scope="row">Facebook Link:</th> 
     <td> 
      <input type="text" name="director_facebook" value="<?php print get_option('director_facebook'); ?>" /> 
     </td> 
     </tr> 
      <tr valign="top"> 
     <th scope="row">Twitter Link:</th> 
     <td> 
      <input type="text" name="director_twitter" value="<?php print get_option('director_twitter'); ?>" /> 
     </td> 
     </tr> 
     <tr> 
     <th scope="row">Display RSS Icon:</th> 
     <td> 
      <input type="checkbox" name="director_rss" <?php if(get_option('director_rss') == true){ print "checked"; } ?> /> 
     </td> 
     </tr> 
     <tr> 
     <th scope="row">Google Analytics Code:</th> 
     <td> 
      <textarea name="director_analytics"><?php print get_option('director_analytics'); ?></textarea> 
     </td> 
     </tr>  
    </table> 
    <p class="submit"> 
    <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> 
    </p> 

</form> 
</div> 
<?php } ?> 

Works Fine。

下面是截圖。

enter image description here

享受乾杯:)

+1

哇感謝分享這個:) –

相關問題