Post formats is one of the exciting features that are coming in WordPress 3.1. But most beginners have no idea what are post formats, why should they matter to you, and how you can take advantage of this awesome feature. Well after going through the alpha version of WordPress 3.1, we have decided to explain the what, whys, and how to’s of Post formats feature that is coming within WordPress 3.1.
帖子格式是WordPress 3.1中令人兴奋的功能之一。 但是大多数初学者都不知道什么是帖子格式,为什么它们对您很重要,以及您如何利用这一出色的功能。 在经历了WordPress 3.1的Alpha版本之后,我们决定解释WordPress 3.1中包含的Post Format功能的内容,原因和方法。
什么是邮政格式? (What are Post Formats?)
Post Formats are meta information that can be used by themes to customize presentation of a post. Ok, now in plain english post format are a method of styling a specific post. By using this feature, you can specify the display “format” of a specific post. This feature expands the micro-blogging aspect of WordPress because now you can have videos, links, images, audios, quotes, statuses, etc. all in one place, and the best part is that they will be styled accordingly.
帖子格式是元信息,主题可以使用这些信息来自定义帖子的显示方式。 好的,现在以简单的英语帖子格式提供一种样式特定帖子的方法。 通过使用此功能,您可以指定特定帖子的显示“格式”。 此功能扩展了WordPress的微博客方面,因为现在您可以将视频,链接,图像,音频,引号,状态等全部集中在一个地方,并且最好的部分是将对它们进行相应的样式设置。
使用范例 (Examples of Usage)
Lets take a look at Digging into WordPress official blog. They have two type of post styles on the homepage. One is a complete post which is displaying an excerpt, just like any other blog. But what is interesting is that they have a specific style of a post that are external links to other blog posts that they find useful for their readers.
让我们来看看Digging into WordPress官方博客 。 它们在主页上有两种类型的帖子样式。 一个完整的帖子就像其他博客一样显示摘要。 但是有趣的是,它们具有特定的帖子样式,这些链接是其他博客文章的外部链接,它们对读者有用。
Blogging is all about sharing resources, and often it is the case where blogger wants to just link to an external resource because he/she finds it useful for their readers. The main problem they face is that they have to make a new post in order to just tell the readers to go to another site. This creates confusion for the end-user because they do not know what type of post it is. Often, the user has to click on the full view of the post just to find out that the author wants them to view an external link. Even though there are tricks like this one, that lets you link to external links from post titles, this post format issue will fix it all. Theme designers can style the “link formats” to be displayed in a different way like Jeff Starr has for Digging into WordPress.
博客是关于共享资源的,博客作者通常只想链接到外部资源,因为他/她发现博客对他们的读者很有用。 他们面临的主要问题是他们必须发表新文章才能告诉读者前往另一个站点。 这使最终用户感到困惑,因为他们不知道帖子的类型。 通常,用户必须单击帖子的完整视图才能发现作者希望他们查看外部链接。 即使有喜欢的招数这一个 ,可以让你从文章标题链接到外部链接,这篇文章的格式问题会解决这一切。 主题设计师可以设置“链接格式”的样式,使其以不同的方式显示,例如Jeff Starr 挖掘WordPress所用的样式。
The power of this feature is too much to describe. Because now you can write short status posts like you would on twitter, and have it styled differently without doing too much of work. If you found a quote that you like, you can share it and have it stand out with one click. The bottom line is that the “post formats” feature will make WordPress a more complete blogging platform.
此功能的强大功能无法描述。 因为现在您可以像在Twitter上一样写简短的状态帖子,并且无需进行过多工作即可设置不同的样式。 如果您找到自己喜欢的报价,则可以共享它,并一键使它脱颖而出。 最重要的是,“帖子格式”功能将使WordPress成为更完整的博客平台。
为什么要使用帖子格式? (Why you want to use Post Formats?)
Post formats replaces the need to use categories to accomplish the similar styling features. Until now, developers hacked WordPress categories to accomplish this effect which ends up creating a lot of clutter and confusion for new bloggers. Using post formats will not only cut down clutter in terms of categories, it will make your blog portable between themes that support those formats.
邮政格式取代了使用类别来实现类似样式功能的需要。 到目前为止,开发人员入侵了WordPress类别以实现这种效果,最终给新博客创建了很多混乱和混乱的地方。 使用帖子格式不仅可以减少类别上的混乱,还可以使您的博客在支持这些格式的主题之间可移植。
It will also make your blog more user-friendly for your readers because your user will know exactly what type of post they are viewing. Furthermore, it will make your blog more lively because you will have different style of posts on your blog page. Right now, most blog post display looks very dull because all posts look alike. The post formats will fill a much needed void within the WordPress powered sites.
这也将使您的博客对读者更加用户友好,因为您的用户将确切知道他们正在查看的帖子类型。 此外,这将使您的博客更加生动活泼,因为您在博客页面上将拥有不同风格的帖子。 目前,大多数博客帖子的显示都非常呆板,因为所有帖子看起来都很相似。 帖子格式将填补WordPress支持的网站中急需的空白。
如何在WordPress 3.1中添加和使用帖子格式 (How to Add and Use Post formats in WordPress 3.1)
Just like post thumbnails, Menus, Custom Backgrounds, and Custom headers, the post formats will also be a theme activated feature. What this means is that this feature will only be available if your theme is compatible.
就像帖子缩略图 , 菜单 , 自定义背景和自定义标题一样 ,帖子格式也将是主题激活功能。 这意味着仅当您的主题兼容时,此功能才可用。
Warning: You must have a fair understanding HTML, CSS, and the functions of the WordPress loop to follow this tutorial.
警告:您必须对HTML,CSS和WordPress循环的功能有一定的了解,才能遵循本教程。
In order to activate “post formats” in WordPress 3.1, you will need to open your theme’s functions.php file and paste the following code:
为了激活WordPress 3.1中的“发布格式”,您将需要打开主题的functions.php文件并粘贴以下代码:
add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
Note: aside, and gallery are not the only available post formats. The available list of post formats are:
注意:除了,画廊不是唯一可用的帖子格式。 可用的帖子格式列表为:
- aside – Typically styled without a title. Similar to a Facebook status update. 放在一边-通常样式不带标题。 类似于Facebook状态更新。
- chat – A chat transcript. chat –聊天记录。
- gallery – A gallery of images. gallery-图片库。
- link – A link to another site. 链接–指向另一个站点的链接。
- image – A single image. 图像–单个图像。
- quote – A quotation. quote –报价。
- status – A short status update, usually limited to 140 characters. Similar to a Twitter status update. 状态–简短的状态更新,通常限制为140个字符。 类似于Twitter状态更新。
- video – A single video. 视频–单个视频。
For the full list of post formats, refer to WordPress Codex.
有关发布格式的完整列表,请参阅WordPress Codex 。
Once you have added this code, you will see a new field in your post write panel in the right hand column where you see publish.
添加此代码后,您将在“撰写”面板的右侧列中看到一个新字段,在该列中您将看到发布。
Upon writing the post, you can change the format and hit publish. This will allow you to display your post in a pre-styled format.
撰写文章后,您可以更改格式并点击发布。 这将使您可以以预先设置的格式显示帖子。
But wait, we have not yet specified these pre-styled post formats anywhere in our theme. So right now, even if you select the format in your WordPress post panel, it will not make a difference because your theme does not know how to display it. For this, we will need to edit our post loop.
但是,等等,我们尚未在主题的任何位置指定这些预样式化的帖子格式。 因此,现在,即使您在WordPress帖子面板中选择了格式,也不会有所不同,因为您的主题不知道如何显示它。 为此,我们将需要编辑后循环。
We are going to be utilizing the conditional tag: has_post_format()
我们将使用条件标签: has_post_format()
if ( has_post_format( 'aside' )) {
// code to display the aside format post here
} else if (has_post_format('gallery')) {
// stuff to display the gallery format post here
} else if (has_post_format('link')) {
// stuff to display the link format post here
}else {
// code to display the normal format post here
}
Now what are you waiting for? Start preparing yourself for this awesome feature. We can only imagine WordPress being used more and more as a micro-blogging platform with new themes that will come out utilizing this feature.
现在你还在等什么? 开始为这个很棒的功能做准备。 我们只能想象WordPress被越来越多地用作具有新主题的微博客平台,这些主题将利用此功能来出现。
其他读物: (Additional Readings:)
WordPress Codex Post FormatsPost types and formats and taxonomies, Oh my!Post Formats vs. Custom Post Types
WordPress Codex发布格式 发布类型和格式以及分类法,哦,天哪! 帖子格式与自定义帖子类型
翻译自: https://www.wpbeginner.com/wp-themes/what-whys-and-how-tos-of-post-formats-in-wordpress-3-1/