如何在管理面板中创建自定义文本表单并将其显示在我的页面上(Wordpress) [英] How to create custom text forms in admin panel and show them on my page (Wordpress)

查看:196
本文介绍了如何在管理面板中创建自定义文本表单并将其显示在我的页面上(Wordpress)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简介
目前,我正在创建我的第一个自定义Wordpress主题。现在,我成功创建了HTML / CSS模板,并将其转换为适合wordpress的模板(包括header.php,index.php,footer.php,functions.php,sidebar.php和page.php)。

Introduction: At this moment I'm creating my first custom Wordpress theme. Now I succesfully created a HTML/CSS template and converted this to fit wordpress (including header.php, index.php, footer.php, functions.php, sidebar.php and page.php).

案例/问题的定义:
在我的主页(index.php)中,我包括几个div,其中填充了文本(纯HTML和CSS)。现在,我希望能够从Wordpress后端的管理面板中手动更改此文本。我已经在管理面板中做了一个额外的子菜单页面。此页面目前完全空白。

Case/Problem definition: At my homepage (index.php), I included several div's filled with text (pure HTML and CSS). Now I want to be able to manually change this text from an admin panel in my Wordpress Back-end. I already made an extra sub-menu page in the admin panel. This page is completely blank at this moment.

简而言之:
如何在我的Wordpress管理面板中填写文本表单,并在特定页面上将其显示出来(

In Short: How to fill in a text form in my Wordpress admin panel and echo this out on a certain page (front-end).

额外
因为我是Wordpress的新手,所以PHP和创建自己的主题不是确定如何执行此操作或如何在线搜索教程(我不知道要搜索的正确术语)。

Extra Since I'm new to Wordpress, PHP and creating your own themes I'm not sure how to do this or how to search for tutorials online (I don't know the correct terminology to search).

感谢所有提示和建议!

推荐答案

在您的 functions.php 添加以下突出显示的代码。这将添加一个twitterid。因此,您可以在自定义主题的任何位置调用自定义管理页面的值:

In your functions.php add the following code that is highlighted. This will add a twitterid. So anywhere in your custom theme you can call the value of the custom admin page:

添加菜单项:

add_action('admin_menu', 'add_global_custom_options');

分配自定义函数以创建表单。

Assign the custom function which will create a form.

function add_global_custom_options()  
{  
    add_options_page('Global Custom Options', 'Global Custom Options', 'manage_options', 'functions','global_custom_options');  
}

创建一个生成表格的函数:

Create a Function Which Generates the Form:

<?php
function global_custom_options()
{
?>
    <div class="wrap">
        <h2>Global Custom Options</h2>
        <form method="post" action="options.php">
            <?php wp_nonce_field('update-options') ?>
            <p><strong>Twitter ID:</strong><br />
                <input type="text" name="twitterid" size="45" value="<?php echo get_option('twitterid'); ?>" />
            </p>
            <p><input type="submit" name="Submit" value="Store Options" /></p>
            <input type="hidden" name="action" value="update" />
            <input type="hidden" name="page_options" value="twitterid" />
        </form>
    </div>
<?php
}
?>

查看您的管理页面。您将在管理菜单中找到一个名为全局自定义选项的新链接。只需以该格式输入值,您就可以在主题文件中使用这些值,例如 get_option('twitterid')。因此,在您的index.php或任何其他主题文件中,您可以执行

View your admin page. You will find a new link in your Admin Menu called "Global Custom Options". Just enter your values in that form and you are good to go for using those values in your theme files like "get_option(‘twitterid’)". So, in your index.php or any other theme file, you can do something like

<?php echo get_option('twitterid') ?>

,它将打印管理页面上文本框中的任何值。

and it will print whatever value is in the textbox on admin page.

这里是教程供参考。

这篇关于如何在管理面板中创建自定义文本表单并将其显示在我的页面上(Wordpress)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆