邪恶的WordPress主题框架

Once you have an idea of how you’d like your blog to appear, it’s time to start hacking on the theme itself. Typically, a WordPress theme needs a number of core files to function—files for the index page, single posts, static pages, and all the bits and pieces that live inside, such as comments and sidebars. WordPress’s core theme, Twenty Ten, contains 22 files in total, and that’s excluding the images. There sure is a lot of work in there!

一旦确定了博客的显示方式,就该开始对主题本身进行黑客攻击了。 通常,WordPress主题需要大量核心文件才能运行-索引页面,单个帖子,静态页面以及其中生活的所有点点滴滴的文件,例如注释和边栏。 WordPress的核心主题“二十”共包含22个文件,这不包括图像。 那里肯定有很多工作!

Savvy developers know that reinventing the wheel is for suckers, and when you want to start off on the right foot, it’s often faster and easier to build on top of a framework. PHP developers have frameworks like CakePHP or CodeIgniter; Ruby geeks have Ruby on Rails; .NET developers have ASP.NET. The WordPress theme community is no exception—theme development frameworks have arisen to make it simpler for you to create your own theme.

精明的开发人员知道,重新设计轮子是为了傻瓜,当您想从右脚开始时,在框架之上进行构建通常会更快,更容易。 PHP开发人员拥有CakePHP或CodeIgniter之类的框架。 Ruby极客使用Ruby on Rails。 .NET开发人员拥有ASP.NET。 WordPress主题社区也不例外-主题开发框架的出现使您更轻松地创建自己的主题。

WordPress theme development frameworks look just like regular themes—dare we say, even a little bit boring—yet underneath their modest facades lies powerful functionality that acts as a scaffold for your own theme development. In this chapter, we’ll look at why frameworks are such a great idea, how to choose the best theme framework for you, and how to augment that framework with our own sexy styles and custom functionality.

WordPress主题开发框架看起来就像常规主题(我们敢说,甚至有点无聊),但其适度外观之下却隐藏着强大的功能,可充当您自己的主题开发的支架。 在本章中,我们将研究为什么框架如此好主意,如何为您选择最佳的主题框架,以及如何使用我们自己的性感样式和自定义功能来扩充该框架。

为什么要使用框架? (Why use a framework?)

I bet you’re busy, right? You’re probably also excited to start your theme development as soon as you can. And as your theme career grows, you’ll appreciate anything that can help you save some time. Theme development frameworks are here to make your life a whole lot easier.

我敢打赌你很忙吧? 您可能也很高兴能尽快开始主题开发。 随着主题事业的发展,您会感激可以帮助您节省时间的一切。 主题开发框架可以使您的生活更加轻松。

Frameworks provide markup, functional elements, and often some basic CSS, all of which you can use as a foundation for your own theme. For beginner themers, using a framework means that you can spend less time putting together your code, and more time concentrating on your design. It’s also a great way to learn about how WordPress themes are put together, especially if you’re fairly new to PHP.

框架提供标记,功能元素,通常还提供一些基本CSS,您可以将所有这些用作自己主题的基础。 对于初学者来说,使用框架意味着您可以花费更少的时间来编写代码,而将更多的时间专注于设计上。 这也是了解WordPress主题如何组合的好方法,特别是如果您刚接触PHP的话。

Later on, once you’ve established yourself as a world-renowned WordPress theme rock star, you’ll find that using a framework saves you time: you’ll spend less time on doing the repetitive work that every theme requires, and more on the finer details of your newest masterpiece.

稍后,一旦您将自己确立为举世闻名的WordPress主题摇滚明星,就会发现使用框架可以节省您的时间:您将花费更少的时间进行每个主题所需的重复性工作,而更多的时间用于最新杰作的细节。

儿童主题:在框架上构建的明智方法 (Child Themes: The Smart Way to Build on a Framework)

Back in ye olden days, if you wanted to modify the output of a WordPress theme, you’d have to edit the theme directly. There were very few opportunities to alter a theme’s markup or functionality without changing the template files. If the theme you started from was upgraded, you’d then have to spend time carefully integrating your alterations back into the newly updated original—hardly the most productive use of your time.

回顾过去,如果您想修改WordPress主题的输出,则必须直接编辑主题。 在不更改模板文件的情况下,几乎没有机会更改主题的标记或功能。 如果您从开始的主题进行了升级,那么您将不得不花费时间仔细地将变更内容重新整合到新近更新的原始内容中,这几乎不是最有效地利用您的时间。

WordPress 2.7 (we’re now up to 3.1) changed all that when it introduced the concept of a child theme—a theme that extends on the capabilities of another theme. At a minimum, a child theme needs only a style sheet (style.css) within its own directory, and another theme specified as the parent. When WordPress builds a page, it’ll take the style sheet from the child theme, and the templates from the parent theme.

WordPress 2.7(我们现在为3.1)在引入子主题的概念时进行了所有更改,该主题扩展了另一个主题的功能。 子主题至少需要在其自己的目录中仅需要一个样式表( style.css ),而另一个主题则应指定为父主题。 当WordPress构建页面时,它将从子主题中获取样式表,并从父主题中获取模板。

But for the more adventurous, child themes can help you go even further, with two ways to override the behavior of the parent. There’s an additional file, functions.php, that’s available for adding your own code to the theme. What’s more, template files stored within the child theme’s directory will override those of the parent. This means that if you’d like to make changes to the parent theme’s markup or functionality, all you need to do is write a custom function, or make your own version of the relevant template—and voilà, complete control.

但是对于更具冒险精神的孩子,主题可以通过两种替代父项行为的方式来帮助您进一步发展。 还有一个附加文件,functions.php,可用于将您自己的代码添加到主题。 而且,存储在子主题目录中的模板文件将覆盖父主题的模板文件。 这意味着,如果您想更改父主题的标记或功能,您所需要做的就是编写一个自定义函数,或者制作自己的相关模板版本,然后完全控制。

Here’s the best bit: while the WordPress community has developed a number of feature-rich frameworks especially for this purpose, any theme can act as a parent. If your favorite theme permits modification in its license, you’re free to go right ahead and use it as a framework for your lovely new theme, without editing the original in any way.

这是最好的一点:虽然WordPress社区已经为此开发了许多功能丰富的框架,但任何主题都可以充当父主题。 如果您喜欢的主题允许对其许可证进行修改,则可以随意进行操作并将其用作可爱的新主题的框架,而无需进行任何原始形式的编辑。

There’s nothing to prevent you from directly modifying a theme framework, if that’s what floats your boat, but the smart money’s on using a child theme as often as you can. Whenever your parent theme’s developer makes an update to their theme, updating yours is as simple as installing the fresh version of the parent. Your child theme will be instantly updated at the same time, meaning that you spend less time worrying about incorporating your changes.

没有什么可以阻止您直接修改主题框架的,这正是您的本事,但是明智的选择是尽可能多地使用子主题。 每当父主题的开发人员对其主题进行更新时,更新主题就像安装父主题的新版本一样简单。 您的孩子主题将在同一时间立即更新,这意味着您可以减少花费在担心合并更改上的时间。

In this chapter, we’ll be keeping a very important maxim in mind: hands off the parent theme! It’s the cleanest, simplest way to build on a theme and avoid tripping over your own toes.

在本章中,我们将牢记一个非常重要的原则:放开父主题! 这是构建主题并避免绊倒自己的脚趾的最干净,最简单的方法。

我如何选择一个好的框架? (How do I choose a great framework?)

You can use any theme as a framework—providing, of course, that its license permits you to do so. That often means that a premium—or paid—theme is a poor choice for anyone who wants to distribute their themes for free. Here are some important points to examine.

您可以将任何主题用作框架,当然,只要其许可证允许您这样做即可。 对于那些想要免费分发主题的人来说,这通常意味着溢价(或已付费)主题是一个糟糕的选择。 这里是一些要检查的重点。

Clean, semantic HTML A theme with valid, semantic HTML means that it’ll be a breeze to style up your theme with your own CSS. If your prospective theme has a demo page, run it through the W3C validator and see what falls out. You should also keep an eye out for plenty of class hooks for you to hang your CSS on, as this will make your job much easier when it comes time to create your child theme.

干净,语义HTML具有有效语义HTML的主题意味着使用您自己CSS设置主题样式非常容易。 如果您的预期主题有一个演示页面,请通过W3C验证器运行它,然后看看有什么问题。 您还应该留意许多类挂钩,以挂起CSS,因为这将使创建子主题的工作变得更加容易。

CSS examples A good framework will ideally come with some minimal CSS you can use as a starter for your own styling. A great framework will have a number of layouts available for you to use; ideally, it will also have different stylistic concerns such as typography, color, and layout placed in separate files, making it simple for you to pick and choose from the defaults.

CSS示例一个理想的框架最好带有一些最小CSS,您可以将它们用作自己的样式的入门。 一个好的框架将提供许多布局供您使用。 理想情况下,它还将具有不同的样式问题,例如版式,颜色和布局放置在单独的文件中,使您可以轻松地从默认值中进行选择。

SEO benefits If you’ve dreamed of seeing your theme on thousands of popular blogs, you can bet that SEO will be uppermost in those bloggers’ minds; it should be right up there in yours, too. Your framework’s markup should follow good SEO practices, such as a sensible use of headings and semantic elements, descriptive title elements, and good use of meta elements.

SEO的好处如果您梦想着在成千上万的流行博客中看到您的主题,那么您可以打赌SEO在这些博客中是最重要的。 它也应该在您的那里。 框架的标记应遵循良好的SEO做法,例如合理使用标题和语义元素,描述性title元素以及适当使用meta元素。

Widget-ready Your framework should include plenty of places for WordPress widgets. Your users will be less than impressed if your theme only permits widgets in sidebars. Choosy bloggers look for themes that support widgets above and below posts, in headers and footers, and indeed anywhere they can squeeze in their favorite gadgets and goodies.

准备好小部件您的框架应包含许多WordPress小部件的位置。 如果您的主题仅允许侧边栏中的小部件,则对您的用户的印象将不那么深刻。 挑剔的博主会寻找主题,这些主题支持帖子上方和下方,页眉和页脚中的小部件,甚至支持他们喜欢的小工具和物品的任何地方。

Plays well with plugins Your choice of framework should, ideally, play nicely with popular plugins. Some frameworks already include CSS for the most popular plugins, and at the very least, the framework developer should have tested the theme on a blog with plenty of plugins installed.

与插件配合使用理想情况下,您选择的框架应该与流行的插件配合使用。 一些框架已经包含了最受欢迎的插件CSS,至少,框架开发者应该已经在博客上测试了主题,并安装了许多插件。

Documentation and support A good theme framework will have documentation and an avenue for support, whether that’s a forum, wiki, mailing list, or even a support ticket system. Take a look around and see what the community’s like—are they helpful angels or cranky trolls? This is especially true if you’re buying a paid theme; why drop all that cash for shabby or non-existent support?

文档和支持好的主题框架将具有文档和获得支持的途径,无论是论坛,Wiki,邮件列表,甚至是支持票证系统。 环顾四周,看看社区的样子-他们对天使或怪异的巨魔有帮助吗? 如果您要购买付费主题,尤其如此。 为什么将所有现金用于破旧或根本不存在的支持?

值得检查的框架 (Frameworks Worth Checking Out)

Although any theme could conceivably be used as a framework, some notable examples have been designed especially for this purpose. We’ll take a look at these now, as well as some child themes that have been created from them.

尽管可以想到将任何主题用作框架,但专门为此目的设计了一些著名的示例。 现在,我们将看看这些内容以及从中创建的一些子主题。

赠品 (Freebies)

Here are just a few of the great free frameworks on offer.

这里只是提供的一些很棒的免费框架。

专题性 (Thematic)

Ian Stewart’s Thematic, shown in Figure 1, is one of the best-known theme frameworks out there, and for good reason: it boasts thousands of users, it has been tested with dozens of popular plugins, and there’s plenty of helpful, free community support. You can grab Thematic from ThemeShaper, which is also home to a huge collection of tutorials about building child themes, as well as creating your own framework.

Ian Stewart的Thematic,如图1所示,是其中最著名的主题框架之一,并且有充分的理由:它拥有成千上万的用户,已经通过数十个流行的插件进行了测试,并且有很多有用的免费社区支持。 您可以从ThemeShaper中获取Thematic,该主题同时还包含了大量有关构建子主题以及创建自己的框架的教程。

Figure 1. A plain Thematic demo, using the default styles

图1.使用默认样式的普通主题演示

Thematic

Thematic child themes are plentiful: Figure 2, Figure 3, and Figure 4 show just how flexible this framework can be.

子主题主题非常丰富:图2,图3和图4展示了该框架的灵活性。

Figure 2. ThemeShaper uses a Thematic child theme

图2. ThemeShaper使用Thematic子主题

Themeshaper

Figure 3. Commune, by Cristian Antohe

图3.克里斯蒂安·安托赫的《 公社》

Commune

Figure 4. The Neutica child theme, by Allan Cole

图4. Neutica儿童主题,作者Allan Cole

Neutica
杂种 (Hybrid)

Justin Tadlock’s Hybrid, shown in Figure 5, boasts plenty of documentation and support, and it’s free and open source. You’ll also find a collection of language translations, plenty of child themes to download and try, and Hybrid-specific plugins to enhance your use of this excellent free theme. Access to an extensive collection of in-depth tutorials and forums costs a reasonable US$25 (NB all prices quoted in this article should be checked before you buy – they may have changed).

贾斯汀·塔德洛克(Justin Tadlock)的Hybrid(如图5所示)拥有大量的文档和支持,并且是免费的开放源代码。 您还将找到语言翻译的集合,大量可供下载和尝试的子主题以及特定于Hybrid的插件,以增强您对这个出色的免费主题的使用。 进入大量深入的教程和论坛的费用为25美元(注意,购买前应检查本文中引用的所有价格-它们可能已更改)。

Figure 5. Hybrid in action

图5.混合动力

Hybrid

You can download Hybrid from Theme Hybrid. While you are there, take a look at some of the lovely child theme examples by Justin; screenshots from two of them can be seen in Figure 6 and Figure 7.

您可以从Theme Hybrid下载主题 。 当您在那里时,看看Justin的一些可爱的儿童主题示例。 其中两个的屏幕截图可以在图6和图7中看到。

Figure 6. Share your thoughts with the world, with Life Collage

图6.通过Life Collage与世界分享您的想法

Life Collage

Figure 7. It’s fun, it’s hip, it’s Old School

图7.很有趣,很时髦,很老

Old School
卡灵顿 (Carrington)

CrowdFavorite’s Carrington framework is open source, and comes in four flavors: one with some graphic design laid in (Figure 8), one with no markup at all, one designed especially for mobile devices, and plain old vanilla. There’s official and community support available, and plenty of documentation for the curious coder.

CrowdFavorite的Carrington框架是开源的,有四种样式:一种具有一些图形设计(图8),一种根本没有标记,一种专门为移动设备设计,还有普通的旧香草。 有官方和社区支持,还有许多关于好奇的编码器的文档。

Figure 8. The blogger- and developer-friendly Carrington Blog

图8.博主和开发人员友好的Carrington博客

Carrington

付费框架 (Paid Frameworks)

These paid frameworks come with stacks of bells and whistles, a strong enterprise and SEO focus, and premium support.

这些付费框架带有许多技巧,强大的企业和SEO重点以及高级支持。

论文 (Thesis)

The Thesis framework from DIY Themes promises to put an end to all your SEO worries, with plenty of options for end users and professional theme developers alike. In Thesis, you make modifications to a custom CSS and functions file within the theme itself, rather than using the child theme method mentioned above, but it’s still a rock-solid framework nonetheless. At the time of writing, Thesis is $87 for personal use and $164 for developers, and there’s a thriving marketplace for Thesis skins. The default Thesis skin is shown in Figure 9.

DIY主题的Thesis框架有望消除您所有SEO的烦恼,并为最终用户和专业主题开发人员提供大量选择。 在Thesis中,您可以在主题本身内对自定义CSS和功能文件进行修改,而不是使用上面提到的子主题方法,但是它仍然是一个坚固的框架。 在撰写本文时,Thesis个人使用的价格为87美元,开发人员的价格为164美元,并且Thesis皮肤的市场蓬勃发展。 默认的论文皮肤如图9所示。

Figure 9. The rock-solid Thesis framework

图9.坚实的论文框架

Thesis

Thesis drives a number of popular blogs; check out some of its high-profile users in Figure 10 and Figure 11 below.

论文推动了许多受欢迎的博客。 请在下面的图10和图11中查看其一些引人注目的用户。

Figure 10. Cute Overload—for the finest in cute imagery

图10.可爱的重载—获得最好的可爱图像

Cute Overload

Figure 11. The compelling content of CopyBlogger

图11. CopyBlogger的引人入胜的内容

CopyBlogger
创世记 (Genesis)

StudioPress’s Genesis framework provides a plain, serviceable theme with numerous included layouts, and requires only a little CSS loving to really shine. Some Genesis-specific widgets help extend this theme well beyond alternative offerings. It’s US$59.95 for your own use, and there’s an official Genesis theme marketplace to sell your child themes. Figure 4.12 and Figure 4.13 show some of the cool variations you can achieve with the Genesis framework.

StudioPress的Genesis框架提供了一个简单易用的主题,其中包含许多包含的布局,并且只需要一点点CSS就可以真正发光。 某些特定于Ge​​nesis的小部件帮助将这一主题扩展到了其他产品之外。 这是$ 59.95美元供您自己使用,并且有一个官方的Genesis主题市场可以出售您的儿童主题。 图4.12和图4.13显示了可以通过Genesis框架实现的一些很酷的变化。

Figure 12. Viewing the Genesis theme demo

图12.查看Genesis主题演示

Genesis

Figure 13. This Genesis child theme is truly enterprising

图13.这个Genesis子主题确实令人进取

Genesis

那么哪个框架是最好的呢? (So which framework is the best?)

C’mon, SitePoint, just tell us which is the best!

来吧,SitePoint,请告诉我们哪个是最好的!

Well, the best theme framework for you to use is, of course, entirely up to you and your needs.

好吧,当然,您可以使用的最佳主题框架完全取决于您和您的需求。

In fact, you might decide that none of them are right for you, and that you’d rather roll your own.

实际上,您可能会认为它们都不适合您,而您宁愿自己动手做。

You tell us what works for you!

您告诉我们什么对您有用!

翻译自: https://www.sitepoint.com/wicked-wordpress-theme-frameworks/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值