如何在WordPress中添加自定义快速编辑功能?
请提供在WordPress中创建和管理自定义快速编辑功能的方法。
-
玖比肆 评论在 WordPress 中添加自定义快速编辑功能需要以下步骤:
1. 打开您的 functions.php 文件,并添加以下代码:
```
function custom_quick_edit_box($column_name, $post_type) {
if ($post_type == 'post') { // 替换 'post' 为您的自定义文章类型
switch ($column_name) {
case 'author': // 添加您要编辑的自定义元素
echo '';
break;
}
}
}
add_action('quick_edit_custom_box', 'custom_quick_edit_box', 10, 2);
```2. 其中,上面的代码中会出现 "作者" 的一段,这是一个示例代码,您可以根据您的需求修改它。
3. 接下来,将以下代码添加到functions.php 以使我们的样式正常工作:
```
add_action('admin_enqueue_scripts', function() {
wp_enqueue_style('custom-quick-edit', get_stylesheet_directory_uri() . '/custom-quick-edit.css');
});
```4. 然后,我们需要创建一个新的样式表custom-quick-edit.css 并添加以下代码:
```
.inline-edit-col-right .inline-edit-col label span.title {
display: inline-block;
width: 25%;
text-align: right;
padding: 5px 10px 5px 0;
}
.inline-edit-col-right .inline-edit-col label select {
width: 70%;
margin-right: 5%;
}
```5. 以上代码将添加一个带标签和下拉框的字段到文章快速编辑中。
6. 最后,在您的自定义文章类型页面,您可以看到“快速编辑”链接。单击它,您可以编辑和保存您的自定义选项。
希望这篇文章对您有所帮助!
2023年 5月 13日 下午11:29
