如何在wordpress主题中添加设置页面
1、创建所需的文件 在进行主题定制前,应该首先创建一个可供自定义的“设置选项页面”。
创建设置选项页的代码需要放置在主题目录下的functions.php文件中。
如果我们的主题名为“OptionPage”,那么functions.php文件的路径为:\wp-content\themes\OptionPage\functions.phph。
我们不需要让wordpress手动加载它,在执行时wordpress会自动加载。
2、建立设置选项页 首先第一步需要在后台建立一个空白页面供我们使用。
我们通过add_aaction来实现这一步。
Actions可以在wordpress执行时的特定时间被响应,例如,当在控制面板创建菜单时,admin_menu就会被响应执行。
因此,可以利用这些来实现我们所需的功能。
这是我们创建选项页的最基本的功能。
// 设置选项页 function themeoptions_admin_menu() {// 在控制面板的侧边栏添加设置选项页链接 add_theme_page("主题设置", "主题选项", 'edit_themes', basename(__FILE__), 'themeoptions_page'); } function themeoptions_page() {// 设置选项页面的主要功能 } add_action('admin_menu', 'themeoptions_admin_menu');?> themeoptions_admin_menu() 是在控制面板的侧边栏中添加一个链接,指向我们创建的选项页:themeoptions_page。
add_theme_page() 的参数为:页面标题:主题设置 菜单标题:主题选项(p.s.为了区分显示,页面与菜单标题我做了不同我命名) 作用功能:edit_themes;Handle(句柄):当前文件;执行的函数:themeoptions_page;现在后台控制面板侧边栏的处就多了一个“主题设置”的菜单,但是现在还是空白的,我们后面要实现的定制内容就在这个空白页面上创建。
3、添加选项和字段 现在我们就可以在刚创建的空白页面上添加我们的选项和字段。
这个页面你可以根据自己的需要进行样式风格化,但在本教程中我们将使用wordpress默认的类,这样可以节省我们的时间并且看起来更加原生。
页面内容的代码需包含在 themeoptions_page() 函数内。
首先,我们先添加一个 class="wrap" 的 div 容器;然后,在头部添加一个默认图标作为作为页面标题;最后是设计表单。
function themeoptions_page() {// here's the main function that will generate our options page?> 主题设置 } 在表单中,首先我们需要添加一个隐藏的值,通过它来检查更新是否已经提交。
然后添加一个提交按钮,这里我也使用wordpress默认的按钮样式。
现在的效果为:现在我们已经创建了设置选项页的基本结构,下面我们开始根据之前制定的内容进行完善:首先,我们要允许主题使用者可以更改颜色方案。
对于这一点,我们需要一个下拉列表提供可用的配色方案。
其次,增加两个广告位的内容,我们需要增加两个文本框来输入图片的URL及广告链接URL。
最后,用户可选择是否显示搜索框。
这一点,我们通过添加复选框来实现。
代码如下:function themeoptions_page() {// 这是产生主题选项页面的主要功能?> 主题设置 主题配色方案 >灰色 >浅蓝 >粉红 图片广告位(1) "/> 广告图片 "/> 广告链接 图片广告位(2) "/> 广告图片 "/> 广告链接 /> 显示搜索框 } 到这里选项页面的内容就已经基本构建完毕了。
4、数据库更新 到目前为止,我们已经创建了一个主题选项页面,下一步要做的就是如何将数据透过POST提交的wordpress数据库。
要做到这一点,需要创建一个新的功能函数themeoptions_update(),这个函数将会被themeoptions_page()调用,所以将下面的代码添加到themeoptions_page()函数的最上面。
if ( $_POST['update_themeoptions'] == 'true' ) { themeoptions_update(); } 下一步是增加一个更新函数。
function themeoptions_update() { // 数据更新验证 update_option('mytheme_colour', $_POST['colour']); update_option('mytheme_ad1image', $_POST['ad1image']); update_option('mytheme_ad1url', $_POST['ad1url']); update_option('mytheme_ad2image', $_POST['ad2image']); update_option('mytheme_ad2url', $_POST['ad2url']); if ($_POST['display_search']=='on') { $display = 'checked'; } else { $display = ''; } update_option('mytheme_display_search', $display); }5、调用选项定制主题5.1 更改配色方案 我们主题的默认样式文件为 style.css,如果使用其他的配色方案,我们需要建立相应的样式文件,例如本例中的 blue.css、pink.css,style.css 为默认的灰色。
为了切换配色方案样式表,需要在主题 header 中加入以下代码:/default.css" type="text/css">/.css" type="text/css">5.2 增加广告位图片 在你想要放置广告的地方添加以下代码:">" height="125" width="125" />">" height="125" width="125" />5.3 是否显示搜索框 在需要放置搜索框的地方添加以下代码,当用户选择显示搜索框时会显示,否则则不显示: 搜索框 "> " /> 6、总结 本文翻译自NET TUTS+文章《How to Integrate an Options Page into your WordPress Theme》,版权归原文作者所有。
为了更容易地学习添加主题选项页的过程,我省略了原文中部分内容,有兴趣的话可以参考原文。
翻译水平有限,...
wordpress 模板和wordpress主题有什么不同
如果想要自己修改风格的话CSS是一定要能会一些的。
至于php代码不需要掌握,但要熟悉WordPress的常用函数标签。
比如哪些数据是用什么函数来调用,以及这个函数里面的参数有什么作用等。
这个不用太担心,网上有很多WordPress的函数使用说明教程,不懂的时候就多搜索。
网上有很多wordpress的企业风格主题和CMS风格主题,你自己可以选个适合的,然后再稍加修改。
至于后台,主题风格跟后台没有关系,后台还是普通的WordPress后台。
不过,配合那些企业风格的主题,便会基本实现企业网站那样的功能。
蛋炒饭怎么做,要用英语翻译,最好用简单的词。
要按下列的步骤:1....
1,prepare two eggs ,some rice ,some oil ,and some seasoning .2,pour some oil into the pan ,and then add in the rice, stir-fry for a short while3,.break the eggs and put it in the pan ,stir-fry for a moment.4,Add in the seasoning and mix them well,Now it is finished.
预装网站问题?
这些英文的内容大概看了一下,主要有以下几点:1、配置wp-config.php文件2、填写配置文件中的数据库、主机名、用户名、密码等你之所以不能创建成功,可能是你的数据库没有建立好或者你的数据库服务器出了问题。
那么你最好检查一下,你的数据库是否正常运行以及在填写相关信息时是否出现错误,细心点,就能按照好了
求介绍博客的英语短文一篇
给个给你参考.介绍blog的作用,出现,好处等的.A blog is a personal diary. A daily pulpit. A collaborative space. A political soapbox. A breaking-news outlet. A collection of links. Your own private thoughts. Memos to the world.Your blog is whatever you want it to be. There are millions of them, in all shapes and sizes, and there are no real rules.In simple terms, a blog is a web site, where you write stuff on an ongoing basis. New stuff shows up at the top, so your visitors can read what's new. Then they comment on it or link to it or email you. Or not.Since Blogger was launched in 1999, blogs have reshaped the web, impacted politics, shaken up journalism, and enabled millions of people to have a voice and connect with others.
请求英文作文: if time can turn back, what will you do ?
With many rearons,we always turn to searching a way which should set us free.If time can turn back,what will you do? You should clean up the wrongs being done,you should enjoy with them who might love you,support you ,encourage you but had gone,and you should be devoted to study by heart so on.But,no measures can be taken by you,that is to say,time can never turn back,your wrongs,you regretness have be done and kept in your mind,the only way you can choose is not to make the same mistakes on one thing.Time as the flow water,love it from now.
复仇者联盟3百度云资源
The black bilesourly bitterrose in Bonaseras throatoverflowed through tightly clenched teethHe used his white linen pocket handkerchief and held it against his lipsHe was standing so when the two young men strode freely up the aisleconfident and cool-eyedsmilingnot giving him so much as a glanceHe let them pass without saying a wordpressing the fresh linen against his mouth.
转载请注明出处51数据库 » wordpress themas
影子爱人34247092