Do you want to add a custom post status for your blog posts in WordPress? Post status is an editorial tool that allows you to organize your articles based on their respective stages during the editorial workflow. In this article, we will show you how to easily add custom post status to blog posts in WordPress.
您是否要为WordPress中的博客帖子添加自定义帖子状态? 发布状态是一种编辑工具,可让您根据文章在编辑工作流程中的各个阶段来组织文章。 在本文中,我们将向您展示如何轻松地将自定义帖子状态添加到WordPress中的博客帖子。
![How to add custom post status in WordPress How to add custom post status in WordPress](https://i-blog.csdnimg.cn/blog_migrate/107319c45074727e39df614306c4e6e6.png)
WordPress中的职位状态是什么?为什么需要它? (What is Post Status in WordPress and Why Do You Need it?)
Post status is an editorial tool that tells WordPress the stage of a blog post during editing. For example, posts that are incomplete are saved with the post status labeled ‘Draft’. When you publish an article, the status changes to ‘Published’.
帖子状态是一种编辑工具,可告诉WordPress编辑期间博客帖子的阶段。 例如,不完整的帖子将以帖子状态标记为“草稿”保存。 发布文章时,状态更改为“已发布”。
![Post status Post status](https://i-blog.csdnimg.cn/blog_migrate/c5a5cc338a273850ace75c58acd9df3d.png)
Post status helps WordPress choose how to handle and display blog posts on your website. For example, it will automatically exclude posts labeled draft from your homepage and other publicly viewable areas of your website.
发布状态可帮助WordPress选择如何在您的网站上处理和显示博客文章。 例如,它将自动从您的主页和网站的其他公共可见区域中排除标有草稿的帖子。
By default, WordPress comes with the following post status that you can use:
默认情况下,WordPress具有以下可以使用的帖子状态:
- Draft – An item that is saved but incomplete and not yet published 草稿–已保存但不完整且尚未发布的项目
- revision.修订版 。
- Pending review – Items that are complete and submitted for review but not yet published. 待审核–已完成但已提交但尚未发布的项目。
- Posts scheduled to be published later.帖子计划以后发布。
- Private – Items marked as private 私人-标为私人的项目
- Trash – Items that are trashed 垃圾箱–垃圾箱
- Inherit – Child pages that automatically inherit status of their parent page. 继承–子页面自动继承其父页面的状态。
Apart from these default post statuses, you can also create your own custom post statuses to improve your editorial workflow. For example, you can add a label ‘Not suitable’ for posts that are complete but not suitable for publication.
除了这些默认的帖子状态之外,您还可以创建自己的自定义帖子状态以改善编辑工作流程。 例如,您可以为完整但不适合发布的帖子添加标签“不适合”。
Having said that, let’s take a look at how to easily create custom post statuses in WordPress.
话虽如此,让我们看一下如何轻松地在WordPress中创建自定义帖子状态。
方法1.使用插件创建自定义帖子状态 (Method 1. Create Custom Post Status Using a Plugin)
This method is easier and recommended for most users. It allows you to create custom post statuses as well as efficiently manage editorial workflow on your multi-author WordPress blog.
此方法更简单,建议大多数用户使用。 它使您可以创建自定义帖子状态,并有效管理多作者WordPress博客上的编辑工作流程 。
The first thing you need to do is install and activate the Edit Flow plugin. For more details, see our step by step guide on how to install a WordPress plugin.
您需要做的第一件事是安装并激活Edit Flow插件。 有关更多详细信息,请参阅有关如何安装WordPress插件的分步指南。
Upon activation, the plugin will add a new menu item labeled ‘Edit Flow’ to your WordPress admin menu. Clicking on it will take you to the plugin’s settings page.
激活后,该插件将在您的WordPress管理菜单中添加一个名为“编辑流程”的新菜单项。 单击它会将您带到插件的设置页面。
![Edit statuses Edit statuses](https://i-blog.csdnimg.cn/blog_migrate/7cd257a0bb5f66616032c26ad2c7909b.png)
Edit Flow comes with a lot of useful features, and you can turn them On/Off from this screen. Go ahead and click on the ‘Edit Statuses’ button under ‘Custom Statuses’ box to continue.
“编辑流”具有许多有用的功能,您可以在此屏幕上打开/关闭它们。 继续并单击“自定义状态”框下的“编辑状态”按钮以继续。
Edit Flow automatically creates the following custom post statuses:
编辑流程会自动创建以下自定义帖子状态:
- Pitch – Used to pitch new article ideas and this status also becomes the default post status of every new post. 推销–用于推销新文章的想法,此状态也成为每个新帖子的默认帖子状态。
- Assigned – You can select an author and mark an article as assigned so that the author can work on it. 已分配–您可以选择作者并将文章标记为已分配,以便作者可以对其进行处理。
- In progress – Writer is working on the post but is not yet available as a readable draft. 进行中– Writer正在撰写帖子,但尚不可读。
![Add new status Add new status](https://i-blog.csdnimg.cn/blog_migrate/909d724988d58d1f8699e273bcd71b5e.png)
You can create your own custom status by providing a name and description in the left column. Once you are done, click on the ‘Add new status’ button to save your changes.
您可以通过在左栏中提供名称和描述来创建自己的自定义状态。 完成后,单击“添加新状态”按钮以保存您的更改。
Your custom status will now appear in the right-hand column, so you can edit or delete it at any time.
现在,您的自定义状态将显示在右侧列中,因此您可以随时对其进行编辑或删除。
![Edit status Edit status](https://i-blog.csdnimg.cn/blog_migrate/b35728f4b481df1d1e8591abb9419f92.png)
Next, you need to go to Posts » Add New page to create a new post. On the post edit screen, click on the ‘Edit’ link next to status option under the ‘Publish’ meta box.
接下来,您需要转到帖子»添加新页面以创建新帖子。 在帖子编辑屏幕上,单击“发布”元框下状态选项旁边的“编辑”链接。
![Select post status Select post status](https://i-blog.csdnimg.cn/blog_migrate/4326485b66dc5957f7f1d8e05f916b41.png)
This will reveal a drop-down menu showing all post statuses that you can select including the custom post status you just created.
这将显示一个下拉菜单,显示所有可以选择的帖子状态,包括刚创建的自定义帖子状态。
You can also see all articles filed under different post statuses by visiting Posts » All Posts page.
您还可以通过访问帖子»所有帖子页面查看以不同帖子状态归档的所有文章 。
![Sort posts by status Sort posts by status](https://i-blog.csdnimg.cn/blog_migrate/19e1c7a943e7fcfee6a01fa7ab7cb7b3.png)
方法2。使用代码创建自定义帖子状态 (Method 2. Create Custom Post Status Using Code)
WordPress has a known bug in the API used to register custom post statuses. It allows you to create custom post status, but you cannot use it in the admin panel. This means that the coding method can get the job done, but it is not as clean, and you will need to change it after it is officially fixed.
WordPress在用于注册自定义帖子状态的API中存在一个已知的错误 。 它允许您创建自定义帖子状态,但是不能在管理面板中使用它。 这意味着编码方法可以完成工作,但是还不够干净,在正式修复后,您需要对其进行更改。
However if you still want to do it manually, then you can continue reading.
但是,如果您仍然想手动进行操作,则可以继续阅读。
This method requires you to add code to your WordPress site. If you haven’t done this before, then take a look at our guide on how to copy and paste code in WordPress.
此方法要求您将代码添加到WordPress网站。 如果您以前没有做过,请查看我们的指南, 了解如何在WordPress中复制和粘贴代码 。
First, you need to add the following code to your theme’s functions.php file or a site-specific plugin.
首先,您需要将以下代码添加到主题的functions.php文件或特定于站点的插件中 。
// Registering custom post status
function wpb_custom_post_status(){
register_post_status('rejected', array(
'label' => _x( 'Rejected', 'post' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Rejected <span class="count">(%s)</span>', 'Rejected <span class="count">(%s)</span>' ),
) );
}
add_action( 'init', 'wpb_custom_post_status' );
// Using jQuery to add it to post status dropdown
add_action('admin_footer-post.php', 'wpb_append_post_status_list');
function wpb_append_post_status_list(){
global $post;
$complete = '';
$label = '';
if($post->post_type == 'post'){
if($post->post_status == 'rejected'){
$complete = ' selected="selected"';
$label = '<span id="post-status-display"> Rejected</span>';
}
echo '
<script>
jQuery(document).ready(function($){
$("select#post_status").append("<option value=\"rejected\" '.$complete.'>Rejected</option>");
$(".misc-pub-section label").append("'.$label.'");
});
</script>
';
}
}
Don’t forget to replace all instances of the word rejected with your own custom post status.
不要忘记用您自己的自定义帖子状态替换所有被拒绝单词的实例。
This code registers a custom post status and after that, it uses jQuery to add it to the admin panel. You can now edit a WordPress post, and you will be able to see it in the status drop-down menu.
这段代码注册了一个自定义帖子状态,然后使用jQuery将其添加到管理面板中。 现在,您可以编辑WordPress帖子,并且可以在状态下拉菜单中看到它。
![Custom post status shown in admin panel Custom post status shown in admin panel](https://i-blog.csdnimg.cn/blog_migrate/ee1de935c65a17e4b1a8cc39a26287e3.png)
We hope this article helped you add custom post status to blog posts in WordPress. You may also want to see our list of 55+ most wanted WordPress tips, tricks, and hacks.
我们希望本文能帮助您将自定义帖子状态添加到WordPress中的博客帖子中。 您可能还希望查看我们的55多个最想要的WordPress技巧,窍门和hack列表 。
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在Twitter和Facebook上找到我们。
翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-add-custom-post-status-for-blog-posts-in-wordpress/