wordpress主题

tech2023-01-08  94

wordpress主题

In this article, we’ll get you started on WordPress theme development, dealing with what you need to learn before you even think about coding.

在本文中,我们将带您开始WordPress主题开发,处理您甚至在考虑编码之前需要学习的知识。

WordPress has become the most popular CMS in the world. As of May 2013, is was used by 52% of the top blogs across the globe, according to a survey carried out by Technorati and Pingdom. This is an increase of 4% over 2012, so it’s clear that the platform continues to rise in popularity.

WordPress已成为世界上最受欢迎的CMS。 根据Technorati和Pingdom进行的一项调查,截至2013年5月,全球52%的顶级博客已使用。 与2012年相比,这一数字增长了4%,因此很明显,该平台的受欢迎程度持续上升。

There are over 65 million WordPress sites in use and, as mentioned, that number continues to grow. So for developers, there’s a clear opportunity to carve out a niche for making WordPress themes and create a valuable addition to their skill set.

超过6500万个WordPress网站正在使用中,并且如上所述,这个数字还在继续增长。 因此,对于开发人员而言,存在一个明确的机会来开拓出制作WordPress主题的利基市场,并为他们的技能创造有价值的补充。

入门 (Getting Started)

In theory, it’s easy to make a theme and it’s something that is getting even simpler as time goes on and support gets better. All you really need to begin is an index.php file and a style.css file—but this won’t make you stand out from the crowd. And if you’re going to venture into learning a new skill, then you might as well do it to the best of your ability, right?

从理论上讲,创建主题很容易,并且随着时间的流逝和支持的提高,它变得越来越简单。 您真正需要开始的只是一个index.php文件和一个style.css文件,但这不会使您脱颖而出。 而且,如果您打算冒险学习一种新技能,那么您最好也尽力做到这一点,对吗?

Before we go any further, if you want to make a great theme, then it’s necessary to have a good working knowledge of HTML and CSS, preferably with experience of coding HTML5 and CSS3. It’s a competitive market and WordPress supports both of these new standards.

在继续进行之前,如果您想制作一个很棒的主题,那么必须具有良好HTML和CSS知识,最好是具有编码HTML5和CSS3的经验。 这是一个竞争激烈的市场,WordPress支持这两个新标准。

If it turns out you have no knowledge of the new standards, you can get up to speed by taking a look at the Jump Start HTML5 series on Learnable or HTML5 & CSS3 for the Real World published by SitePoint.

如果事实证明您对新标准一无所知,可以通过查看由SitePoint发布的关于Learnable的Jump Start HTML5系列或针对真实世界HTML5和CSS3来快速掌握。

It’s also necessary to understand that your theme will have to be compatible with the latest version of WordPress and perhaps some legacy versions too, as not everyone upgrades to the latest straight away, due to potential compatibility issues. Because everyone’s set up is different, compatibility issues may not affect everyone, so it may depend on what themes and plugins are installed on the site, or even on the server setup.

还需要了解,您的主题必须与WordPress的最新版本以及某些旧版本兼容,因为由于潜在的兼容性问题,并不是每个人都立即升级到最新版本。 因为每个人的设置都不同,所以兼容性问题可能不会影响每个人,因此它可能取决于站点上安装的主题和插件,甚至取决于服务器设置。

WordPress市场 (The WordPress Marketplace)

WordPress coding standards are pretty strict; security is a must and it’s necessary to look into licensing, popular plugins, and the WordPress APIs before making a start on the coding side of things. In other words, do your homework. Don’t assume that because you can code, that’s all you’re going to need. It’s also worth giving some thought to how well you will be able to support the theme.

WordPress编码标准非常严格。 安全是必不可少的,在开始进行编码方面之前,有必要研究许可,流行的插件和WordPress API。 换句话说,做功课。 不要以为因为可以编写代码,所以这就是您所需要的。 还值得考虑一下您将如何支持该主题。

Will you have the time to:

您是否有时间去:

Create updates and patches

创建更新和补丁 Respond to customer queries and issues with their installation

回应客户的询问和安装问题 Maintain the theme and continue development

保持主题并继续发展 Include code comments, which are vital to creating a theme

包括代码注释,这对于创建主题至关重要

Take a look at the documentation on the WordPress site before getting started, so you’ll be aware of exactly what you’re getting into. Anyone can become a WordPress developer, but it’s a rigorous process if you want to get the theme approved and entered into the official theme directory.

在开始使用之前,请先查看WordPress网站上的文档 ,以便您确切了解所要学习的内容。 任何人都可以成为WordPress开发人员,但是如果您想要使主题获得批准并输入到官方主题目录中 ,则这是一个严格的过程。

Also, have a good look through WordPress’s coding standards to ensure that you really are up to the task before. This could help you avoid much frustration later on.

另外,请仔细阅读WordPress的编码标准,以确保您确实能够胜任之前的工作。 这可以帮助您避免以后遇到很多挫败感。

准备自己 (Preparing Yourself)

Now that you know what you’re getting into, and assuming you’ve prepared so far by brushing up on necessary coding standards, take a look around at the structure of some really good existing themes.

既然您已经知道要进入的领域,并且假设您已经准备了必要的编码标准,那么现在就来了解一下一些非常好的现有主题的结构。

Themeforest are currently billing a theme called ‘X’ as being the best out there. It’s quite complex, but worth taking a look. The best place to start, however, is with the current default Twenty Fourteen theme (which is one of three themes bundled with WordPress 3.8) to get a good overview of the basic WordPress structure.

目前,Themeforest正在向名为“ X”的主题收取最高的费用。 这很复杂,但是值得一看。 但是,最好的起点是使用当前的默认二十四主题 (这是与WordPress 3.8捆绑在一起的三个主题之一),以很好地了解WordPress的基本结构。

You’ll be working with about 12 core files when you begin the build process. These include:

开始构建过程时,将使用约12个核心文件。 这些包括:

header.php

header.php index.php

index.php sidebar.php

sidebar.php footer.php

footer.php archive.php (for categories, posts, authors, dates and so on)

archive.php(用于类别,帖子,作者,日期等) single.php (individual posts)

single.php(个人帖子) comments.php

comments.php page.php (for static pages rather than posts)

page.php(用于静态页面而不是帖子) search.php

search.php 404.php

404.php style.css

style.css functions.php (allows changing of core functionality without editing core files)

functions.php(允许在不编辑核心文件的情况下更改核心功能)

Most of the above are self-explanatory for those that have developed a site in the past. There are also a series of PHP template tags that you insert into your code, allowing for dynamic content. When in doubt, refer to the codex to see how tags work and which are suitable for what you want to achieve.

对于那些过去开发过站点的人来说,以上大多数都是不言自明的。 您还可以在代码中插入一系列PHP 模板标签 ,以实现动态内容。 如有疑问,请参考编解码器以查看标签如何工作以及哪种标签适合您想要实现的目标。

做对了 (Doing it Right)

If you don’t follow WordPress’s submission guidelines, your theme will not be accepted. One requirement is that you don’t spell WordPress in any other way than I have. It seems a small requirement, but it’s an important one; no lower case P, no laziness, it has to be spelled that way and that’s that or it won’t be accepted.

如果您不遵循WordPress的提交准则,则您的主题将不被接受。 一个要求是您不要以除我以外的任何其他方式拼写WordPress。 这似乎是一个很小的要求,但这是一个重要的要求。 没有小写字母P,没有懒惰,必须以这种方式拼写,就是那样,否则它就不会被接受。

While I mentioned backwards compatibility earlier, this must be minimised to one major previous version. The current version is 3.8, so that means that you shouldn’t go back beyond 3.7 when it comes to making your theme compatible with previous versions.

我在前面提到向后兼容性时,必须将其最小化到一个主要的先前版本。 当前版本是3.8,这意味着在使主题与以前的版本兼容时,您不应回到3.7以上。

It’s also vital that your coding is clean and error-free. There must be no "_doing_it_wrong()" notices, errors relating to .php, or JavaScript errors. It’s also recommended to validate HTML and CSS (though validation-free code is not expected; the default Twenty Fourteen theme for example has 23 CSS validation errors). For more information check out out the code quality guidelines.

编码干净无错误也很重要。 不得有“ _doing_it_wrong()”通知,与.php相关的错误或JavaScript错误。 还建议验证HTML和CSS(尽管不要求使用无需验证的代码;例如,默认的二十四主题有23个CSS验证错误)。 有关更多信息,请查看代码质量准则 。

WordPress API (WordPress APIs)

If you’re going to write a WordPress theme, then it’s an excellent idea to learn the APIs inside out. There are plenty of them and they are separated into sections and topics and cover the functions that are involved and necessary to build a theme.

如果您要编写WordPress主题,那么最好由内而外学习API。 它们很多,它们分为几个部分和主题,并涵盖了构建主题所涉及和必需的功能。

Mostly, you’ll be concentrating on the following:

通常,您将专注于以下方面:

Options

选件 Settings

设定值 Theme customization

主题定制 Shortcodes

简码 Widgets

小部件

However, there are literally tons more, so you should take a look at each of them and decide what you need before you begin to build the theme.

但是,从字面上看,还有更多,因此,在开始构建主题之前,您应该查看一下它们并确定所需的内容。

下一步是什么? (What’s Next?)

Now that you know some of what’s involved before you even get started building a theme, the next step is to look into languages, licensing, and structure. Or you could just get on with the coding and get a taste for it to see for sure if it’s something you would like to carry on with first. ## Alternative Resources

现在,您甚至在开始构建主题之前就已经了解了其中涉及的一些内容,下一步是研究语言,许可和结构。 或者,您可以继续进行编码并对其进行尝试,以确保可以确定它是否是您想首先进行的。 ##替代资源

If you want to create a theme but don’t want to go through the hassle of learning the ins and outs of the codex, APIs, and compatibility issues, then you can always ‘cheat’. There are a few sites that allow you to build your own theme without going to a huge amount of trouble. These include Ultimatum, which is a drag and drop builder that you can use without any coding knowledge. It does of course come at a price, namely $65 for a starter license and £125 for Pro (lifetime) membership—so there are other options open to you if you find it too challenging trying to code your own theme.

如果您想创建一个主题但又不想经历学习法典,API和兼容性问题的麻烦,那么您总是可以“作弊”。 有一些站点可让您构建自己的主题而不会造成很多麻烦。 其中包括Ultimatum ,这是一个拖放构建器,您无需任何编码知识就可以使用它。 当然,它的确要付出一定的代价,即65美元的入门许可和125英镑的Pro(终身)会员资格—因此,如果您尝试编写自己的主题难度太大,那么还有其他选择可供您选择。

下次 (Next Time)

In a future article we’ll look at code structure in more detail, submission processes, what to do if your theme is rejected, and language support. There’s so much involved when it comes to building a theme that if you want to compete, you need to build a great one. Later on we’ll also take a closer look at resources that can help you build and test your theme and more.

在以后的文章中,我们将更详细地讨论代码结构,提交过程,主题被拒绝时的操作以及语言支持。 建立主题涉及很多事情,如果您想竞争,就需要建立一个出色的主题 。 稍后,我们还将仔细研究可帮助您构建和测试主题的资源。

Update: The article was updated to remove reference to a possible permissions issue with WordPress 3.8, as this was not correct.

更新:本文已更新,以删除对WordPress 3.8可能的权限问题的引用,因为这是不正确的。

翻译自: https://www.sitepoint.com/so-you-think-you-know-how-write-wordpress-theme/

wordpress主题

相关资源:jdk-8u281-windows-x64.exe
最新回复(0)