user3274745
user3274745

Reputation: 361

Error in php code( building wordpress theme from scratch book)

I was following the Book building wordpress theme from scratch.An options page is created through this method in the wordpress admin panel .There is an error present due to which nothing appears inside it.

Firsly this is added to the functions.php of wordpress:

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

Secondly theme-options.php is created which contains this:

<?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__, 
 'wptuts_landing_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/>
  </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 } ?>

The director options page is created however there is nothing inside it.

The page should show up like this:enter image description here However the page is like this : enter image description here Could you please tell me the problem and a fix to it.

Upvotes: 3

Views: 156

Answers (1)

user3274745
user3274745

Reputation: 361

I found the solution and would like to post it for anyone else who encounters the problem.

There was no WordPress error.However the problem was due to the add_submenu_page call where the function director_settings_page should be called instead of wptuts_landing_settings_page.

Upvotes: 2

Related Questions