Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am creating a theme for a client and it has a custom front page that has a slider and displays the services they offer. I am looking to add an options page where the client can easily update the slider images, service titles, descriptions and images. I have seen this functionality on other themes and am having trouble trying to implement it. I have followed a few different tutorials and I understand how to add the page to the menu, but am unsure how to get the form to update the information on the front page.

Most recently, I followed this tutorial exactly but could not get it to work. When I hit submit, it says "error: options page not found". I saw this in a similar question here, but while the answer solved the error message, it still wasn't updating the information on the front page.

Are there any ideas on how to do this? Or any tutorials that would be helpful? I've been looking but most of the tutorials are outdated or deal with the Settings API and not custom fields.

The code I'm using is from this tutorial from Webdesigner Depot. The main problem I have is that the inputted text does not get saved.

In functions.php:

add_action('admin_init', 'theme_options_init');
add_action('admin_menu', 'theme_options_add_page');

function theme_options_init(){
    register_setting( 'sample_options', 'sample_theme_options');
}

function theme_options_add_page(){
    add_theme_page( __( 'Theme Options', 'sampletheme' ),
                   __('Theme Options', 'sampletheme'),
                   'edit_theme_options', 'theme_options',
                   'theme_options_do_page');
}

function theme_options_do_page() { 
    global $select_options; 
    if (!isset($_REQUEST['settings-updated']))
        $_REQUEST['settings-updated'] = false;
    ?>
    <div>
        <?php screen_icon(); echo "<h2>". __('Custom Theme Options', 'customtheme')."</h2>";?>
        <?php if ( false !== $_REQUEST['settings-updated']) : ?>
        <div>
        <p><strong><?php_e('Options saved', 'customtheme');?></strong></p>
        </div>
        <?php endif;?>
        <form method="post" action="">
            <?php settings_fields('sample_options');?>

            <?php $options = get_option( 'sample_theme_options');
        ?>
            <table>
                <tr valign="top">
                    <th scope ="row">
                        <?php _e('Display Intro Paragraph', 'customtheme');?>
                    </th>
                    <td>
                        <input id="sample_theme_options[showintro]" name="sample_theme_options[showintro]" type="checkbox" value="1"
    <?php checked( '1', $options['showintro'] ); ?>
                    </td>
                </tr>

                <tr valign="top">
                    <th scope="row">
                        <?php _e( 'Intro Paragraph', 'customtheme' ); ?>                    </th>
                    <td>
                        <textarea id="sample_theme_options[introtext]"
    class="large-text" cols="50" rows="10" name="sample_theme_options[introtext]">
                        <?php echo esc_textarea( $options['introtext'] ); ?></textarea>
                    </td>
                </tr>
            </table>
        <p>
            <input type="submit" value="<?php _e( 'Save Options', 'customtheme' ); ?>" />
        </p>
        </form>
    </div>
<?php }

At the top of header.php:

<?php $options = get_option('sample_theme_options'); ?>

And in home.php:

<?php if ($options['showintro'] == 1) { ?>
                <div id="introtext">
                    <?php echo $options['introtext'] ?>
                </p>
                </div>
            <?php } ?>
share|improve this question
    
Post your code please. –  s_ha_dum Feb 24 at 17:50
    
There are mountains of tutorials and framework for these things. Please try to elaborate on actual code you are trying to implement and how it fails for you. –  Rarst Feb 24 at 17:50
    
Sorry, added code. I've looked at lots of tutorials but am having no luck. The main problem is that the text on the front page does not update. –  clancimus Feb 24 at 18:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.