php 在没有 Web 界面的 Drupal 中切换主题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/886382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Switching themes in Drupal without the web interface
提问by burnt1ce
I'm in the process of learning php and creating themes.
我正在学习 php 和创建主题。
Unfortunately, while I was editing a theme that i was currently using in drupal, I made a mistake in the theme such that nothing shows up anymore, even if i were to hit drupal/index.php. I want to change my broken drupal theme to a working one but i'm unable to do so because I can't even view the administration section.
不幸的是,当我正在编辑一个我目前在 drupal 中使用的主题时,我在主题中犯了一个错误,以至于没有再显示任何内容,即使我点击了 drupal/index.php。我想将损坏的 drupal 主题更改为可用的主题,但我无法这样做,因为我什至无法查看管理部分。
回答by Lendrick
The How To reset your theme via the databasepage on Drupal.org has instructions for changing your theme directly from the SQL prompt.
该如何通过数据库设主题页面上Drupal.org有直接从SQL提示更改主题的说明。
It's not immediately clear whether this will work in the most recent version of Drupal, so back up your database before attempting this.
目前还不清楚这是否适用于最新版本的 Drupal,因此在尝试此之前备份您的数据库。
回答by Olav
The easiest way to change your frontend theme is to set it in your sites/default/settings.php:
更改前端主题的最简单方法是在您的站点/默认/设置.php 中设置它:
$conf['theme_default'] = 'minelli';
回答by Khaled Al Hourani
Or if you are using Drupal 6, removing/moving the broken theme folder will make Drupal change the theme to the default theme (Garland).
或者,如果您使用的是 Drupal 6,删除/移动损坏的主题文件夹将使 Drupal 将主题更改为默认主题(Garland)。
回答by x3ja
In terms of sorting your current problem, here's a simple way to do it that should work... Let's say your current theme is called "custom_theme".
在对您当前的问题进行排序方面,这里有一个简单的方法应该可以工作...假设您当前的主题称为“custom_theme”。
- Go to your theme directory ("
sites/default/themes" probably) - Backup your development theme (i.e. move it elsewhere, if you're using Linux command line do something like "
mv custom_theme custom_theme.bak") - Copy the garland theme to here and name it the same as your broken theme (if using LInux command line, something like this should work "
cp -a ../../../themes/garland ./custom_theme" - Try viewing your site now. It should now use garland instead of your broken theme.
- 转到您的主题目录(
sites/default/themes可能是“ ”) - 备份您的开发主题(即将它移到别处,如果您使用的是 Linux 命令行,请执行诸如“
mv custom_theme custom_theme.bak”之类的操作) - 将 garland 主题复制到此处并将其命名为与损坏的主题相同的名称(如果使用 LINUX 命令行,类似这样的操作应该可以“
cp -a ../../../themes/garland ./custom_theme” - 立即尝试查看您的网站。它现在应该使用花环而不是你破碎的主题。
As others have said before, it's also highly recommended that you use a different theme for admins as you do for normal users (in case you break stuff). Select a safe admin theme (like garland) and then you can nearly always get to the admin interface if you're playing with theming.
正如其他人之前所说的那样,强烈建议您为管理员使用不同的主题,就像为普通用户所做的那样(以防万一)。选择一个安全的管理主题(如花环),然后如果您正在玩主题,您几乎总是可以进入管理界面。
回答by tsilavina
you can also insert a new login form in your theme by including this code:
您还可以通过包含以下代码在您的主题中插入一个新的登录表单:
`<?php
if(!user_is_logged_in() ){
print drupal_render(drupal_get_form('user_login'));
}else{
print "You are already logged in!";
}?>`
anywhere in the page.tpl.phpfile of your broken theme, then register with your admin credentials;)
在page.tpl.php您损坏的主题文件中的任何位置,然后注册您的admin credentials;)
回答by Mudassar Ali Sahil
Please also see the following stack over flow issue. it is related to them
另请参阅以下堆栈溢出问题。它与他们有关
- Changing Drupal's theme and keeping Garland as the admin theme?
- Changing the Admin Theme in Drupal 6 Directly in Database
Now here is solution : Remove the files of the bad theme and clear the cache. After clearing the cache you will be able to login again.
现在这里是解决方案:删除坏主题的文件并清除缓存。清除缓存后,您将能够再次登录。
The main difficulty is that you have to clear the cache without being logged in.
主要的困难是您必须在未登录的情况下清除缓存。
Try one of the methods for clearing the cache described in Clearing Drupal's cache
IF Not then Try this one :
如果不是,那么试试这个:
If you have drush, the command to type would be
如果你有 drush,输入的命令是
drush vset theme_default garland
Either on the commandline, or via an administration interface (eg PHPMyAdmin) enter the following query
在命令行或通过管理界面(例如 PHPMyAdmin)输入以下查询
UPDATE system SET status=1 WHERE name = 'garland';
Then either:
然后:
UPDATE variable SET value='s:7:"garland"' WHERE name = 'theme_default';
TRUNCATE cache;
TRUNCATE cache_bootstrap;
TRUNCATE cache_block;
Note that 's:7' refers to the length of the following string. Modify as needed. This is database surgery, tricky stuff. OR If you are using per-user themes, and you've just messed it up for yourself as admin, try
请注意,'s:7' 指的是以下字符串的长度。根据需要进行修改。这是数据库手术,棘手的东西。或者,如果您使用的是每个用户的主题,而您只是以管理员身份将其搞砸了,请尝试
UPDATE users SET theme='garland' WHERE uid = '1';
Be careful, as getting either of those lines wrong can mess things up just as badly.
小心,因为弄错任何一条线都会把事情搞得一团糟。
Cheers!
干杯!
Mudassar Ali
穆达萨阿里
回答by Aleksander Belov
Maybe using two themes in parallel will help.
也许并行使用两个主题会有所帮助。
Set one for the "user frontend" - the one you are developing at /admin/build/themes, another one standard, like garland, which you are NOT going to change, as a "administration backend": /admin/settings/admin.
为“用户前端”设置一个 - 您正在开发的一个/admin/build/themes,另一个标准,如花环,您不会改变它,作为“管理后端”:/admin/settings/admin。
If you happen to break the theme you're developing, you just go to the admin area (/admin), it will switch back to garland.
如果您碰巧破坏了正在开发的主题,只需转到管理区域 ( /admin),它就会切换回 garland。
回答by supervacuo
It's worth mentioning that if you're using the "Sections" module to apply different themes to different parts of the site, the instructions given on the Drupal site won't necessarily work — you may find that moving the problem theme directory out of the way is the only method of seeing the admin interface properly.
值得一提的是,如果您使用“ Sections”模块将不同的主题应用于站点的不同部分,则 Drupal 站点上给出的说明不一定有效——您可能会发现将问题主题目录移出方式是正确查看管理界面的唯一方法。
回答by Andrioid
As far as I know, theme settings are stored in the database, as well for each individual user. The quickest way to get rid of a theme is probably removing it from the theme path.
据我所知,主题设置以及每个用户的主题设置都存储在数据库中。摆脱主题的最快方法可能是将其从主题路径中删除。
Just move it onto your desktop and Drupal should be able to detect that your requested theme is missing and point you to the default instead.
只需将其移动到您的桌面上,Drupal 应该能够检测到您请求的主题丢失并指向默认主题。
Update: Tried this on my Drupal 5 installation, it turned out 'clean'. I suggest copying a working Drupal theme into your theme directory (make a copy first).
更新:在我的 Drupal 5 安装上试过这个,结果是“干净的”。我建议将一个可用的 Drupal 主题复制到你的主题目录中(先复制一份)。

