【问题标题】:Place Wordpress "Site Title" function within "Theme Options" page在“主题选项”页面中放置 Wordpress“站点标题”功能
【发布时间】:2012-06-08 19:05:50
【问题描述】:

我在 Wordpress 中创建了一个“theme-options.php”页面,可以在 WP API“外观”设置菜单下找到该页面。在 this 页面上,我想在 Settings > General-Options 页面( >网站标题标语/副标题)可以在此处编辑(在我的主题选项页面上)并保存..

我该如何实现这一目标?到目前为止,我有这个,它显示了所需的框和信息,但没有正确保存/更新。我错过了什么?

theme-options.php

// Build our Page
function build_options_page() {

// Page Structure
   ob_start(); ?>
     <div class="wrap">
       <?php screen_icon();?>
       <h2>Theme Options</h2>

       <p><b><label for="blogname"><?php _e('Site Title') ?></label></b></p>
       <p><input name="blogname" type="text" id="blogname" value="<?php form_option('blogname'); ?>" class="regular-text" />  
       <span class="description"><?php _e('The name of your site.') ?></span></p> 
       <br />

       <p><b><label for="blogdescription"><?php _e('Tagline or Subheading') ?></label></b></p>
       <p><input name="blogdescription" type="text" id="blogdescription"  value="<?php form_option('blogdescription'); ?>" class="regular-text" /> 
       <span class="description"><?php _e('A brief description of your site.') ?></span></p> 
       <p class="submit">
       <input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes'); ?>" />
       </p>

     </div>
   <?php
   echo ob_get_clean();
   ?>
}

【问题讨论】:

    标签: php html css wordpress themes


    【解决方案1】:

    此示例使用 Profile 页面来显示和修改 blognameblogdescription,但应该非常直接地移植到您的代码中。

    add_action( 'show_user_profile', 'show_extra_profile_fields', 1 );
    add_action( 'edit_user_profile', 'show_extra_profile_fields', 1 );
    
    function show_extra_profile_fields( $user ) { 
        ?>
        <table class="form-table">  
            <tr>
                <th><label for="user_address">Site Title</label></th>
                <td>
                    <input type="text" name="blogname" id="blogname" value="<?php echo esc_attr( get_option('blogname') ); ?>" class="regular-text" /><br />
                    <span class="description"></span>
                </td>
            </tr>
            <tr>
                <th><label for="user_zip">Tagline</label></th>
                <td>
                    <input type="text" name="blogdescription" id="blogdescription" value="<?php echo esc_attr( get_option( 'blogdescription' ) ); ?>" class="regular-text" /><br />
                    <span class="description"></span>
                </td>
            </tr>       
        </table>
        <?php 
    }
    
    add_action( 'personal_options_update', 'save_extra_profile_fields' );
    add_action( 'edit_user_profile_update', 'save_extra_profile_fields' );
    
    function save_extra_profile_fields( $user_id ) {
    
        if ( !current_user_can( 'edit_user', $user_id ) )
            return false;
    
        update_option( 'blogname', $_POST['blogname'] );
        update_option( 'blogdescription', $_POST['blogdescription'] );
    }
    

    【讨论】:

    • 我采纳了您的建议,并稍微修改了原始代码以符合我的要求。谢谢大家!
    • @Rob :也许你可以发布你的工作代码作为答案,所以我们在这里记录了正确的解决方案......很高兴我能提供帮助:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-20
    • 1970-01-01
    • 1970-01-01
    • 2011-09-08
    相关资源
    最近更新 更多