wordpress后台增加自定义设置选项,填入保存后,前台调用内容方法

主题function.php文件中写入以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
add_action('admin_menu', 'create_theme_menu_function');
function create_theme_menu_function(){
    add_menu_page( '自定义信息设置', '自定义信息设置', 'edit_theme_options', 'xw_menu1','display_theme_menu_function','',199);
}
function display_theme_menu_function(){ ?>
    <form method="post" name="xw_menuform" id="xw_menuform" action="options.php">
    <h2>基本信息</h2>
    <p>
    <span style="color:blue;font-weight:bold;">安全提示:</span><br/><textarea rows="3" cols="60" name="laoniu_anquantishi" ><?php echo get_option('laoniu_anquantishi'); ?></textarea></br>
    <span style="color:blue;font-weight:bold;">友情提示:</span><br/><textarea rows="3" cols="60" name="laoniu_youqingtishi" ><?php echo get_option('laoniu_youqingtishi'); ?></textarea></br>
    <span style="color:blue;font-weight:bold;">联系我们:</span><br/><textarea rows="3" cols="60" name="laoniu_lianxi" ><?php echo get_option('laoniu_lianxi'); ?></textarea></br>
    <span style="color:blue;font-weight:bold;">定制服务:</span><br/><textarea rows="6" cols="60" name="laoniu_dingzhi" ><?php echo get_option('laoniu_dingzhi'); ?></textarea></br>
    <span style="color:blue;font-weight:bold;">关于:<?php echo get_bloginfo ( 'title' ); ?>:</span><br/><textarea rows="8" cols="80" name="laoniu_guanyu" ><?php echo get_option('laoniu_guanyu'); ?></textarea></br>
    </p>
    <?php wp_nonce_field('update-options'); ?>
    <input type="hidden" name="action" value="update" />
    <input type="hidden" name="page_options" value="laoniu_anquantishi,laoniu_youqingtishi,laoniu_lianxi,laoniu_dingzhi,laoniu_guanyu" />
    <p class="submit">
        <input type="submit" name="option_save" value="<?php _e('保存设置'); ?>"/>
    </p>
    </form>
<?php }

前台调用方法:

在主题文件你想显示得地方使用以下代码:

1
2
3
4
5
6
                <div style="background-color:#C5FEBA;color:#5ACA44;padding:5px 0px 5px 0px;">
                <div>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo get_option('laoniu_anquantishi');?></div>
                <div>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo get_option('laoniu_youqingtishi');?></div>
                <div>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo get_option('laoniu_lianxi');?></div>
                <div style="color:#FF8C00">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo get_option('laoniu_dingzhi');?></div>
                </div>

注:根据自己需求修改,关键代码就是

1
<?php echo get_option('你自定义的option');?>
原文链接:https://xiaohost.com/4197.html,转载请注明出处。
0

评论0

请先