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
    • 267
    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:

    <!--?php
    function setup_theme_admin_menus() {
        add_menu_page('Theme settings', 'Example theme', 'manage_options',
            'tut_theme_settings', 'theme_settings_page');
    
        add_submenu_page('tut_theme_settings',
            'Front Page Elements', 'Front Page', 'manage_options',
            'tut_theme_settings', 'theme_front_page_settings');
    }
    
    function theme_settings_page() {
    
    }
    ?-->
    

    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

    <div class="wrap">
        <?php screen_icon('themes'); ?> <h2>Front page elements</h2>
    
    <form method="POST" action="">
        <table class="form-table">
            <tr valign="top">
                <th scope="row">
                    <label for="num&amp;_elements">
                        Number of elements on a row:
                    </label>
                </th>
                <td>
                    <input type="text" name="num&amp;_elements" size="25" />
                </td>
            </tr>
        </table>
       </form>
            </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.

    <!--?php $posts = get_posts(); ?-->
    
    <p></p><li class="front-page-element" id="front-page-element-placeholder">
        <label for="element-page-id">Featured post:</label>
        <select name="element-page-id">
            <!--?php foreach ($posts as $post) : ?-->
                <option value="<?php echo $post-<ID; ?>">
                    <!--?php echo $post-<post_title; ?-->
                </option>
            <!--?php endforeach; ?-->
        </select>
        <a href="#">Remove</a>
    </li>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: