在主题激活时将小部件添加到自定义 WordPress 侧边栏? [英] Add widgets to custom WordPress sidebars on theme activation?

查看:27
本文介绍了在主题激活时将小部件添加到自定义 WordPress 侧边栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理 WordPress 3.0 多站点安装.每个新博客都将使用相同的主题,稍作修改(自定义论文安装,如果重要的话).我正在尝试尽可能自动化每个新博客的设置过程.

I'm working on a WordPress 3.0 multi-site installation. Each new blog will use the same theme with slight modifications (a custom Thesis install, if it matters). I'm trying to automate the set-up process for each new blog as much as possible.

为此,我想自动将小部件添加到我的自定义侧边栏和启用小部件的页脚.如果小部件可以预先设置参数/内容,我或博客所有者可以进入小部件面板进行编辑,那就更好了.

To that end, I'd like to automatically add widgets to my custom sidebars and widget-enabled footers. It'd be even better if the widgets could have pre-set parameters/content, that I or the blog owner could then go into the Widgets panel and edit.

我找了很多遍,一直没能想出一种方法来完成这项工作.

I've searched high and low and haven't been able to figure out a way to make this work.

推荐答案

通过使用 schema.php,我已经能够做到这一点.您可以通过在 wp-admin/includes/schema.php 中找到该文件来找到它.在此文件中,您将找到在安装过程中安装的所有数据库行.因此,这是一个 3 步过程.

I have been able to do this by working with schema.php. You can find this file by locating it in wp-admin/includes/schema.php. In this file you will find all the database rows which are installed during installation. Therefore this is a 3-step process.

1)首先安装一个完全正确的.然后查看您的数据库并找到它创建的行.通常这些将在 _options 表中创建.然后找到schema.php文件并滚动到第320行<代码>//3.0'page_for_posts' =>0,'page_on_front' =>0,

1)First install one completely correct. Then look at your database and find the rows that it creates. Usually these will be created in the _options table. Then find the schema.php file and scroll to line 320 // 3.0 'page_for_posts' => 0, 'page_on_front' => 0,

2) 遵循相同的语法,否则您的整个安装将崩溃.然后只需从您的 _options 表中复制粘贴即可.语法如下:page_for_posts="option_name" 和 0="option_value".

2)Follow the same syntax or your entire installation will crash. Then just copy paste from your _options table. The syntax is as follows: page_for_posts="option_name" and 0="option_value".

当您匹配完 schema.php 中的所有新行后,安装一个新站点.新站点将自动将所有新行安装到数据库中.

When you are finished matching all your new rows in the schema.php install a new site. The new site will automatically install all your new rows into the database.

3)(这适用于您使用插件的情况)最后,当您确定拥有所需的所有插件时.返回 schema.php 并找到第 238 行 'active_plugins' =>array(), 将 array() 更改为 ->(复制并粘贴active_plugins"行 - option_value' 部分)

3)(This applies if you are using plugins)Finally, when you are sure you have all the plugins you need. Go back to schema.php and find row 238 'active_plugins' => array(), change array(), to -> (copy and paste row "active_plugins" - the option_value' part)

因此,当您创建网站时,您的所有插件都会立即安装.

Therefore all your plugins will be installed instantly when your sites are created.

总结...1)完全完成一个站点 2)找到新的数据库行 3)正确编辑 schema.php 和 upgrade.php 4)安装一个新站点.

To summarize...1)finish one site completely 2)Find your new database rows 3)edit schema.php and upgrade.php correctly 4)install a new site.

******一如既往地确保备份您的网站并始终测试测试测试

******as always make sure you backup your site and always TEST TEST TEST

让我知道这是否令人困惑.我将它用于我的工作,我花了几周的时间发现它才能完美地工作.如果您有更多问题并想直接问我,您可以给我发电子邮件.看看我的简历.

Let me know if this is confusing. I use it for my job and it took me a couple weeks of discover to get this working perfectly. If you have more question and you want to ask me directly you can email me. Look at my bio.

您还可以通过 wp-admin/include/upgrade.php 自动化帖子和页面 - 这样您也可以在安装时安装小部件/小部件代码:)

You also can automate posts and pages through wp-admin/include/upgrade.php - this way you can install your widgets/widget code on install as well :)

这篇关于在主题激活时将小部件添加到自定义 WordPress 侧边栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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