wordpress快速建站_您的WordPress主题灵活还是快速?

wordpress快速建站

This article is part of a series created in partnership with SiteGround. Thank you for supporting the partners who make SitePoint possible.

本文是与SiteGround合作创建的系列文章的一部分。 感谢您支持使SitePoint成为可能的合作伙伴。

If you’ve developed WordPress themes for mass distribution, you might have come across the problem of finding the perfect balance between building performant themes and building feature-rich, media-heavy products for your customers.

如果您已经开发了用于大规模分发的WordPress主题,则可能会遇到在为客户构建性能主题与构建功能丰富,媒体密集的产品之间找到完美平衡的问题。

Let’s look closer into what the tension might be all about and how you can find ways to compromise between creating fast-loading themes and giving users the flexibility and easy customization options they love and expect.

让我们仔细研究一下可能造成的紧张局势,以及如何找到在创建快速加载主题与为用户提供他们所钟爱和期望的灵活性和便捷自定义选项之间折中的方法。

编写WordPress主题时,灵活性和性能难道不是很容易吗? (Are Flexibility and Performance at Odds When Coding WordPress Themes?)

I will start by saying that my discussion is not going to be about performance in relation to an entire WordPress website, which might include a number of different factors like finding a great hosting provider, implementing caching mechanisms, leveraging both back-end and front-end techniques, etc.

我首先要说的是,我的讨论将不会涉及整个WordPress网站的性能,其中可能包括许多不同的因素,例如找到优秀的托管服务提供商 ,实施缓存机制,利用后端和前端最终技术等

Also, the topic is not about the performance of WordPress themes you code from scratch either for your own use or for a specific client. In these particular cases you tailor your themes to the specific needs of yourself or your individual client, which should make performance optimizations easy to accommodate.

同样,该主题与您为自己使用或特定客户端从头编写的WordPress主题的性能无关。 在这些特殊情况下,您可以根据您自己或您的个人客户的特定需求来定制主题,这将使性能优化易于实现。

Rather, my focus will be on WordPress themes you code for the general public, to be distributed on WordPress.org or an online marketplace. The scenario is one where you, as the theme developer, have no control over how your theme is going to be used and customized.

相反,我的重点是您为公众编写的WordPress主题,这些主题将在WordPress.org或在线市场上发布。 在这种情况下,您作为主题开发人员无法控制主题的使用方式和自定义方式。

But why could coding for performance clash with coding themes for the public?

但是,为什么性能编码与面向公众的编码主题冲突?

On the whole, performance requires you to:

总体而言,性能要求您:

  • stick to simple designs

    坚持简单的设计
  • include a limited number of features into your themes (more features are likely to require more processing power and resources, all of which impacts on theme performance)

    在主题中包括数量有限的功能(更多功能可能需要更多的处理能力和资源,所有这些都会影响主题性能)
  • add the minimum number of page templates for a theme to function (fewer templates require fewer resources, which is good for performance)

    为主题添加最少数量的页面模板以使其起作用(更少的模板需要较少的资源,这对性能很有好处)
  • perform as few database queries as possible (querying the database takes time)

    执行尽可能少的数据库查询(查询数据库需要时间)
  • limit the number and size of images and other media, which are notoriously heavy files

    限制图像和其他媒体文件的数量和大小,它们是众所周知的笨重文件
  • minimize the number of HTTP requests (each round trip to the server and back takes some time with obvious negative consequences on performance).

    最大限度地减少HTTP请求的数量(每次往返服务器和返回服务器都需要花费一些时间,从而对性能产生明显的负面影响)。

On the other hand, a considerable number of your theme’s users are likely more entrepreneurial than tech minded. Therefore, what they might be looking for is a product they can turn into pretty much anything without so much as one line of code, with lots of functionality out of the box, breathtaking photo and video assets, super delightful parallax and other animation effects, and such like.

另一方面,您主题的相当多的用户可能比技术思维更具有企业家精神。 因此,他们可能正在寻找的产品是,无需一行代码就可以将几乎任何东西变成一件事情,并且具有开箱即用的许多功能,令人惊叹的照片和视频资产,超令人愉悦的视差和其他动画效果,像这样

To give theme users all the flexibility they would like could come with some performance costs. But let’s go into a few specific points that illustrate how this can happen and how you can find some middle ground for a successful outcome.

为主题用户提供他们想要的所有灵活性可能会带来一些性能成本。 但是,让我们进入一些特定的点,以说明这是如何发生的以及如何为成功的结果找到一些中间立场。

主题是外观,插件是功能 (Themes are for appearance, plugins for functionality)

Although a number of reputable WordPress experts have been throwing some well-argued criticisms against the so-called kitchen sink themes — that is, those multipurpose themes that can become anything to anybody by offering any functionality under the sun — the demand for them is still going strong.

尽管许多著名的WordPress专家对所谓的厨房水槽主题 (即那些可以在阳光下提供任何功能的东西变成任何东西的多用途主题)进行了激烈争论的批评 ,但对它们的需求仍然存在变得强大。

Themes that give users the ability to easily add social media buttons, SEO features, contact forms, price tables, etc., while attracting a lot of attention from buyers, don’t come without some serious drawbacks.

使用户能够轻松添加社交媒体按钮,SEO功能,联系表单,价格表等的主题,同时吸引了众多买家的注意力,这些主题并非没有严重的缺点。

In particular, this kind of WordPress theme comes tightly coupled with plugins specifically built for it, or even integrated directly into the theme. This practice is widely frowned upon for the following reasons:

特别是,这种WordPress主题与专门为其创建的插件紧密结合在一起,甚至直接集成到该主题中。 由于以下原因,人们普遍不赞成这种做法:

  • Some of the plugins that come bundled with a theme can have vulnerabilities that put theme users at risk. If the theme doesn’t come with specific plugins installed it’s less open to such risks

    与主题捆绑在一起的某些插件可能具有使主题用户处于危险之中的漏洞。 如果主题没有安装特定的插件,则不太可能面临此类风险
  • A super important drawback of tight integration between themes and plugins is what Ren Ventura identifies as theme lock. Here’s his explanation of this problem:

    Ren Ventura将主题和插件紧密集成的一个超级重要缺点是主题锁定 。 这是他对这个问题的解释:

    A super important drawback of tight integration between themes and plugins is what Ren Ventura identifies as theme lock. Here’s his explanation of this problem:

    Ren Ventura将主题和插件紧密集成的一个超级重要缺点是主题锁定 。 这是他对这个问题的解释:

    Theme lock occurs when a WordPress user cannot change his or her theme without gutting most of the site’s functionality. Once the theme is deactivated, it deactivates things like shortcodes and custom post types that were registered by the theme. Without these features that the user has heavily incorporated into the site, things fall apart.

    当WordPress用户在不破坏网站大部分功能的情况下无法更改其主题时,就会发生主题锁定。 停用主题后,它会停用主题已注册的短代码和自定义帖子类型之类的东西。 如果没有用户已大量整合到站点中的这些功能,事情就会崩溃。

    As a consequence, when you change theme, a lot of the stuff you thought it was part of your website content disappears with the old theme. For instance, if your theme offered the ability to add testimonials to your website, once you change theme all the content related to your testimonials will be gone. Not nice.

    结果,当您更改主题时,许多您认为是网站内容一部分的内容随旧主题消失了。 例如,如果您的主题提供了向您的网站添加推荐的功能,则一旦更改主题,与您的推荐相关的所有内容都将消失。 不太好。

  • And of course, bloat and hence performace costs. Let’s say you don’t need a testimonials section on your website. Yet, all the code that makes that functionality work in the theme is still there: it takes up space on your server, which ultimately costs money.

    当然,膨胀和性能成本也很高。 假设您不需要网站上的“推荐”部分。 但是,使该功能在主题中起作用的所有代码仍然存在:它占用了服务器上的空间,最终导致成本上升。

A great maxim the Theme Review Team (i.e., the volunteers who review themes submitted on the WordPress.org themes repo) rightly enforces is: keep functionality separate from appearance. Plugins deal with functionality, themes with appearance. Getting rid of all the complication will improve theme performance and at the same time make it easier for users to install and configure WordPress themes.

主题审查小组(即审查在WordPress.org主题仓库上提交的主题的志愿者)正确地执行的一个最大原则是: 保持功能与外观分开。 插件处理功能,主题处理外观。 消除所有复杂性将提高主题性能,同时使用户更容易安装和配置WordPress主题。

您的用户不需要大量的主题选项(但是他们可能不知道这一点) (Your users don’t need tons of theme options (but they might not know this))

Until not long ago, WordPress themes included rather complicated theme option pages to enable users to make all sorts of modifications with a button click.

直到不久之前,WordPress主题还包括相当复杂的主题选项页面,使用户可以通过单击按钮进行各种修改。

These days, thanks to a momentous decision taken by the Theme Review Team on WordPress.org in 2015, most themes offer theme options using the WordPress Customizer, which makes possible live previewing the changes as they’re being made by users.

如今,由于主题审查团队在WordPress.org上于2015年做出的重大决定 ,大多数主题都使用WordPress Customizer提供了主题选项,从而可以实时预览用户所做的更改。

Unfortunately, the kitchen sink mentality that ruled the old theme option pages has started to migrate to the Customizer, which you can now see as also starting to get filled up with all sorts of settings.

不幸的是,支配旧主题选项页面的厨房水槽思路已经开始迁移到定制程序,您现在可以看到它也开始充满各种设置。

Although non technical customers love theme options to make changes to their themes, sometimes too many options available bring more problems than they seemingly solve:

尽管非技术客户喜欢使用主题选项来更改其主题,但是有时可用的选项太多会带来比他们似乎无法解决的问题更多的问题:

  • Too many options can paralyze users who are not too familiar with core principles of website design.

    太多的选择可能会使那些不太熟悉网站设计核心原理的用户瘫痪。
  • It can take more time than expected to set up and configure a theme.

    设置和配置主题所需的时间可能超出预期。
  • It’s easy to make mistakes like choosing the wrong colors, making text unreadable, etc.

    容易出错,例如选择错误的颜色,使文本不可读等。
  • Users might add too many fonts to their themes, thereby spoiling the design and slowing down the website.

    用户可能会在主题中添加太多字体,从而破坏设计并减慢网站速度。
  • More options means adding more functionality to the theme, thereby impacting on its performance.

    更多选项意味着为主题添加更多功能,从而影响其性能。

Although your customers might not accept this at first, you are the theme designer, therefore you should be the one who is best placed to make the important design decisions for your theme.

尽管您的客户起初可能不会接受,但是您是主题设计师,因此您应该是最能为主题做出重要设计决策的设计师。

A well-calibrated number of theme options should be sufficient to let your customers make some targeted and carefully predefined (by you) modifications to personalize the theme and make it their own.

经过充分校准的主题选项数量应足以使您的客户进行一些有针对性的,(由您)精心预定义的修改,以个性化主题并使其成为自己的主题。

实施智能图形优化技术 (Implement smart graphics optimization techniques)

Images are likely to put the heaviest weight on theme performance compared to template files, scripts and styles. Just run any theme through Pingdom’s Speed Test tool to verify this.

与模板文件,脚本和样式相比,图像可能对主题性能的影响最大。 只需通过Pingdom的Speed Test工具运行任何主题即可进行验证。

However, a generous use of full-screen, bold images is hardly surprising. Images add huge aesthetic value to themes and customers are drawn to a theme largely on the basis of its visual impact.

但是,慷慨地使用全屏,大胆的图像不足为奇。 图像为主题增添了巨大的美学价值,并且很大程度上基于其视觉效果吸引了客户。

Although it’s hard to resist the power of great graphics, the guidelines below can help you code faster themes without necessarily sacrificing aesthetics (too much):

尽管很难抗拒出色图形的力量,但以下准则可以帮助您编写更快的主题,而不必牺牲美观(太多):

  • Using as few images as possible is always a good guiding principle.

    使用尽可能少的图像始终是一个很好的指导原则。
  • Take advantage of CSS blend modes, filters, and semi-transparent overlays on low-resolution images to mask pixelation and enhance their visual appearance. You can also try to experiment with CSS blend modes and filters on HTML elements and text rather than images to create stunning visual effects wherever possible.

    利用CSS 混合模式滤镜和低分辨率图像上的半透明覆盖层来掩盖像素并增强其视觉外观。 您还可以尝试在HTML元素和文本(而不是图像) 尝试CSS 混合模式过滤器,以尽可能创造出惊人的视觉效果。

  • Make sure the images are of the appropriate format and optimized for web.

    确保图像具有适当的格式并针对网络进行了优化。

  • Where appropriate, use CSS sprites to combine your images into a larger image and therefore reduce HTTP requests.

    在适当的地方,使用CSS精灵将您的图像组合成更大的图像,从而减少HTTP请求。

  • Try implementing lazy loading for images. Doing so will achieve faster page load, and if users don’t scroll to the location of the <img> tag, the image won’t need to be downloaded at all. To lazy load images in WordPress you can choose from a number of good plugins, such as Lazy Load, a3 Lazy Load and Rocket Lazy Load.

    尝试实现图像的延迟加载 。 这样做可以加快页面加载速度,并且如果用户不滚动到<img>标签的位置,则根本不需要下载图像。 要在WordPress中延迟加载图片,您可以从许多不错的插件中进行选择,例如Lazy Loada3 Lazy LoadRocket Lazy Load

使客户支持和教育成为您的力量Struts (Make customer support and education your pillars of strength)

Instead of feeding your customers lots of confusing and time-consuming theme options, try offering full support and education on how to use your themes, image optimization, WordPress 101, etc.

与其给客户提供许多令人困惑且费时的主题选项,不如提供有关如何使用主题,图像优化,WordPress 101等的全面支持和教育。

You can do so using:

您可以使用:

  • blog posts

    博客文章
  • downloadable guides

    可下载的指南
  • video tutorials

    影片教学
  • FAQs on your website

    您网站上的常见问题解答
  • a ticket system for more specific issues that might arise while using your themes.

    票证系统,用于在使用主题时可能出现的更具体的问题。

Sharing the basic know-how about your products and the platform you build for is a great way of making your themes easy to use for your customers and contributes to generate a high level of trust, which is at the core of a healthy and successful business.

共享有关您的产品和所构建平台的基本知识是一种使主题易于为客户使用并有助于建立高度信任的好方法,这是健康成功事业的核心。

有时灵活性会胜过性能 (Sometimes Flexibility Wins over Performance)

There may be a limited number of cases when you don’t think compromising some flexibility for the sake of a small performance gain is a good idea.

在少数情况下,您不认为为了获得较小的性能而牺牲一些灵活性是一个好主意。

A couple of examples come to mind.

我想到了两个例子。

编写DRY代码时可能会使您的客户不满意 (When writing DRY code could make your customers unhappy)

The first example comes from Tom McFarlin, a well-known WordPress theme developer and author.

第一个示例来自著名的WordPress主题开发人员和作家Tom McFarlin

In his blog he explains why he decided to include a long list of WordPress template files, thereby going against the DRY coding principle (and also impacting negatively on performance to some extent) while developing his theme Meyer.

在他的博客中,他解释了为什么他决定包括一长串WordPress模板文件 ,从而违背了DRY编码原则(并且在一定程度上发展了Meyer时违反了性能)。

Meyer was targeted at bloggers and digital publishers without much WordPress technical knowledge. Knowing that lack of coding experience would not have stopped this audience from tinkering with his theme, Tom McFarlin thought of a way to make things easier for them. He provided his customers with a generous number of template files they could easily copy and paste into a WordPress child theme for customization without hacking the original theme.

Meyer的目标读者是没有太多WordPress技术知识的博客作者和数字发布者。 汤姆·麦克法兰(Tom McFarlin)知道缺乏编码经验并不会阻止他们修改他的主题,因此他想到了一种使他们更轻松的方法。 他为客户提供了大量模板文件,他们可以轻松地将其复制并粘贴到WordPress子主题中以进行自定义,而不会破坏原始主题。

McFarlin writes:

麦克法林写道:

If the templates are defined in the base theme — rather than, say, a bunch of developer-ish conditionals — users are going to have an easier time basing their templates off of something that already exists …

如果模板是在基本主题中定义的,而不是像一堆开发人员式的条件那样定义的,则用户将可以更轻松地将其模板基于已经存在的东西...

So if I had to sum this up in some concise way, I’d say that I — like many developers — want to keep my code as DRY as possible, but there’s a tradeoff that comes with doing so in the context of WordPress theme development.

因此,如果我必须以一种简洁的方式来总结一下,我会说,与许多开发人员一样,我想让我的代码尽可能保持DRY,但是在WordPress主题开发的背景下,这是一个折衷方案。 。

And I don’t think that staying DRY is the best way to go about it if you’re going to be marketing a product to a wide audience.

而且,如果您要向广泛的受众推广产品,我不认为保持DRY是最好的方法。

Know Your Customer — the Blogger.

了解您的客户-Blogger

静态源代码具有更好的性能,但不要在公共主题中使用它 (Static source code is better for performance but don’t use it in your public themes)

My second example of when not to compromise flexibility for some performance gain in your WordPress themes is based on performance advice from the Codex.

我的第二个示例是基于Codex的性能建议,何时不为了获得WordPress主题的性能而牺牲灵活性。

You’ll find some great performance tips there, but there’s one I wouldn’t recommend you use, at least if you’re going to release your theme to the general public.

您会在此处找到一些出色的性能提示,但我不建议您使用这些提示,至少在要将主题发布给公众的情况下不建议使用。

It goes like this:

它是这样的:

  • Can static values be hardcoded into your themes? This will mean you have to edit code every time you make changes, but for generally static areas, this can be a good trade off.

    可以将静态值硬编码到您的主题中吗? 这意味着您每次进行更改时都必须编辑代码,但是对于通常是静态区域,这可能是一个不错的折衷方案。

    • For example, your site charset, site title, and so on.

      例如,您的网站字符集,网站标题等。

    • Can you hardcode menus that rarely change? Avoiding functions like wp_list_pages() for example.

      您可以对很少更改的菜单进行硬编码吗? 例如,避免使用类似wp_list_pages()函数。

Codex — WordPress Optimization/WordPress Performance

Codex — WordPress优化/ WordPress性能

Avoiding unnecessary calls to the database and optimizing your SQL queries are excellent practices every theme should follow.

避免不必要地调用数据库并优化SQL查询是每个主题都应遵循的优秀实践。

If your theme runs a bit slow, try looking for problematic database queries that take too long to execute. You can use a plugin like Query Monitor in your development environment to help you with this task.

如果您的主题运行有点慢,请尝试查找有问题的数据库查询,这些查询需要花费太长时间才能执行。 您可以在开发环境中使用诸如Query Monitor之类的插件来帮助您完成此任务。

However, hardcoding bits of information like site title, menu items, etc., is out of the question. Even if your users never change that info once it’s set, they need to set it at least once and they rightly expect to do so using WordPress dynamic capabilities.

但是,诸如站点标题,菜单项等信息的硬编码是不可能的。 即使您的用户从未更改过该信息,也需要至少设置一次,并且他们正确地希望使用WordPress动态功能进行更改。

Furthermore, even if your theme’s users were prepared to dig into the source code, they would have to hack the theme files to add the required data. This is almost never a good idea, not least because all changes would be overwritten on the next theme update.

此外,即使您主题的用户已准备好研究源代码,他们也将不得不修改主题文件以添加所需的数据。 这几乎不是一个好主意,尤其是因为所有更改都将在下一次主题更新时被覆盖。

结论 (Conclusion)

Coding WordPress themes for the general public may involve catering for diverse and sometimes incompatible needs: those of your customer base, of web performance, hence the needs of visitors of those websites that use your themes, and even your own needs as WordPress theme designer and creator.

为公众编写WordPress主题可能涉及满足多样化甚至有时不兼容的需求:客户群的需求,网络性能,因此使用主题的网站的访问者的需求,甚至是WordPress主题设计者和您自己的需求。创作者。

In this article I’ve expressed my views on how to address the dilemma WordPress theme developers might face between the demands of flexibility and those of performance.

在本文中,我就如何解决WordPress主题开发人员可能面临的灵活性和性能需求之间的困境表达了自己的看法。

翻译自: https://www.sitepoint.com/are-your-wordpress-themes-flexible-or-fast/

wordpress快速建站

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值