Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Adding settings to template

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 337
    Comment on it

    Hello reader's today we will discuss about "Adding settings to template" .

    Add this code to your theme's functions.php file:

    1. <!--?php
    2. function setup_theme_admin_menus() {
    3. add_menu_page('Theme settings', 'Example theme', 'manage_options',
    4. 'tut_theme_settings', 'theme_settings_page');
    5.  
    6. add_submenu_page('tut_theme_settings',
    7. 'Front Page Elements', 'Front Page', 'manage_options',
    8. 'tut_theme_settings', 'theme_front_page_settings');
    9. }
    10.  
    11. function theme_settings_page() {
    12.  
    13. }
    14. ?-->

    The above function sets up the menu and hooking it to wordpress action admin_menu.

    The below code define how to build your setting page

    1. <div class="wrap">
    2. <?php screen_icon('themes'); ?> <h2>Front page elements</h2>
    3.  
    4. <form method="POST" action="">
    5. <table class="form-table">
    6. <tr valign="top">
    7. <th scope="row">
    8. <label for="num&amp;_elements">
    9. Number of elements on a row:
    10. </label>
    11. </th>
    12. <td>
    13. <input type="text" name="num&amp;_elements" size="25" />
    14. </td>
    15. </tr>
    16. </table>
    17. </form>
    18. </div>

    First, you have to create the element for editing the settings for one main page block to serve as a template for the elements that are added by the user.
    Then Add this code right between the closing table tag and the closing form tag right after it.

    1. <!--?php $posts = get_posts(); ?-->
    2.  
    3. <p></p><li class="front-page-element" id="front-page-element-placeholder">
    4. <label for="element-page-id">Featured post:</label>
    5. <select name="element-page-id">
    6. <!--?php foreach ($posts as $post) : ?-->
    7. <option value="<?php echo $post-<ID; ?>">
    8. <!--?php echo $post-<post_title; ?-->
    9. </option>
    10. <!--?php endforeach; ?-->
    11. </select>
    12. <a href="#">Remove</a>
    13. </li>

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: