自定义WordPress主题而不更改它?
4 个回答
- 投票数
-
- 2010-08-13
虽然您不能不对其进行修改就不能对其进行修改,但是您可以通过创建子主题来隔离要更改的部分.总结:
- 使用"父"主题在同级上创建主题目录,
- 在新目录中创建一个
style.css
文件,该文件的注释中带有一个Template:
声明,命名您的父主题和一个@import url(../%parent-theme%/style.css)
从父主题导入CSS, - 在WordPress管理控制台中激活新主题,
- 添加新文件和/或将文件从父主题目录复制到子主题目录,并根据自己的喜好对其进行修改,并且
- 就是这样!
我可以为您提供更多详细信息,但基本上,这个家伙在解释 如何创建儿童主题方面做得非常好对我来说更好,只是将您指向它.
要升级父主题时,只需升级即可;它将使您的孩子主题保持完整.当然,如果子主题对父主题的更改太大和/或如果您复制和修改了主题文件并在新版本中进行了更新,则您的子主题可能无法完美运行,如果不对其进行修改也不会获得新功能,但这是一个从每次开始都要好很多!
希望有帮助.
While you can't modify it without changing it, you can isolate the parts you change by creating a Child Theme. In summary:
- Create a theme directory on peer with your "parent" theme,
- Create a
style.css
file in your new directory that has aTemplate:
declaration in the comments naming your parent theme and an@import url(../%parent-theme%/style.css)
to import the CSS from the parent theme, - Activate your new theme in the WordPress admin console,
- Add new files and/or copy files from your parent theme directory to your child theme directory and modify them to your preference, and
- That's it!
I could give you lots more details but basically this guy does a really good job of explaining How to Create a Child Theme so better for me just to point you to it.
When you want to upgrade the parent theme just upgrade; it will leave your child theme in-tact. Of course your child theme may not work perfectly if they've changed the parent too much and/or if you copied and modified theme files they updated in the new version you won't get the new functionality without modifying them too, but it's a lot better from starting over each time!
Hope that helps.
-
儿童主题是恕我直言的方式Child themes are the way to go IMHO
- 2
- 2010-09-01
- Ryan Gibbons
-
- 2010-08-21
如果要更改的只是一点CSS,则可以在主题目录内创建一个自定义CSS文件.在主题的标题中包含您的自定义css文件,并仅在自定义css文件中写入新的声明,从而覆盖主题的默认css声明.
默认样式表
body{background:white;width: 960px;margin: 25px auto;}
自定义样式表
body{width:800px;}
您的浏览器将分别为两个样式表进行http调用,并以列出的顺序应用样式.无论最后执行什么声明,都将覆盖在它们之前所做的声明.因此,请确保在header.php中包含任何其他样式表之后,再添加自定义样式表.
如果您最终要更改诸如archive.php或page.php之类的模板文件,则MikeSchinkel的答案将允许您在发布新版本时更新主题,而不会丢失您的修改.但是,如果您只想更改某些CSS,则此方法会很好用.只需确保在更新主题目录之前保存您的自定义样式表即可.
If all you want to change is a little css, you can create a custom css file inside the theme directory. Include your custom css file in the theme's header, and write new declarations in the custom css file only, thereby overwriting the theme's default css declarations.
Default stylesheet
body{background:white;width: 960px;margin: 25px auto;}
Custom stylesheet
body{width:800px;}
Your browser will make separate http calls for the two stylesheets and apply styles in the order they are listed. Whatever declarations are made last will overwrite declarations made before them. So make sure to include your custom stylesheet after any other stylesheets are included in header.php.
If you are going to end up changing template files like archive.php, or page.php, MikeSchinkel's answer will let you update your theme if a new version is released, without loosing your modifications. But if all you want is to change some css, This method will work well. Just make sure that you save your custom stylesheet before updating the theme directory.
-
如果您修改的主题不是您的主题,则可能会出现问题,因此您的更改可能会在主题更新时被覆盖.This might be problematic if the theme you modify is not your theme, so your changes might get overwritten on theme updates.
- 1
- 2010-09-06
- hakre
-
- 2017-02-17
您绝对可以创建一个子主题.子主题使您的主主题保持其原始格式.
我个人所做的是,我使用的是MyThemeShop中的高级WordPress主题.在这种情况下,我将style.css和主题选项文件保持不变.我只是将文件的数据复制到另一个文件,并命名有点不同.例如,如果我使用SociallyViral主题创建其子主题,则将复制其style.css文件中的数据并将其保存到另一个名为childstyle.css的文件中.
此后,我现在将设计特定的功能,并可以通过在childstyle.css文件中添加更多功能来重新设计主题.
这将使我的原始style.css文件保持原样,并使我能够以原始格式进行更新.
You can definitely create a child theme. A child theme keeps your main theme in its original format.
What I personally do is, I am using a premium WordPress theme from MyThemeShop. In that, I keep my style.css and theme options file as it is. I just copy the file's data to another file and name it a little different. For example, if I am using SociallyViral Theme, for creating its child theme, I will copy the data from its style.css file and save it to another file naming it childstyle.css.
After this, I will now design specific functions and can redesign my theme by adding more functionalities in the childstyle.css file.
This keeps my original style.css file as it is and enables me to update it in the original format.
-
我不确定"我将从其style.css文件中复制数据"是什么意思,但通常仅将那些与父"不同"的样式添加到子主题就足够了–子主题的样式添加更改和/或覆盖父项的样式.顺便说一句:您的答案如何为6年前已经接受的答案添加任何内容?I'm not sure what you mean with "I will copy the data from its style.css file" but usually it is enough to only add those styles to the child theme that are *different* from the parent – the child theme's styles add to and/or override the parent's styles. By the way: how does your answer add anything to the answer that was already **accepted 6+years ago**?!
- 0
- 2017-02-17
- tillinberlin
-
- 2010-09-01
如果您对尝试上述步骤的良好"实验室练习"感兴趣.有一个很好的逐步指南,用于根据默认WordPress创建子主题3.x交付了二十个主题.这是一个简单但有用的子主题(命名为三十).结果将二十个主题从两列主题扩展到三列主题.它还有一些新的标题图片.
If your interested in a good 'Lab Exercise' for trying out the steps described above. There is nice step by step guide for creating a child theme off the default WordPress 3.x delivered theme twentyten. It is a simple but useful child theme (named thirtyten). The result extends twentyten theme from a two column theme to a three column theme. It also has some new header pictures.
我找到并下载了一个主题.但是我想对CSS进行一些调整,以稍微更改设计,颜色等.我应该如何去做,同时仍然能够在不丢失更改的情况下更新主题.