我创建了一个自定义帖子类型,我想在编辑器页面的标题下方和文本编辑器上方显示一些文本。我该怎么做?
我尝试使用add\\u meta\\u box,但无法将其移动到编辑器上方。
我创建了一个自定义帖子类型,我想在编辑器页面的标题下方和文本编辑器上方显示一些文本。我该怎么做?
我尝试使用add\\u meta\\u box,但无法将其移动到编辑器上方。
最好的方法是使用JavaScript注入元素。
以下是该页面标记的要点:
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-2">
<div id="post-body-content">
<div id="titlediv">
... other stuff ...
</div>
<div id="postdivrich" class="postarea">
... other stuff ...
</div>
</div>
</div>
</div>
Thetitlediv
是标题。这个postdivrich
是内容编辑器。您想在它们之间插入一些内容。使用jQuery,这非常简单。只需告诉它在titlediv
:jQuery(function($) {
var text_to_insert = "This is some text you\'ll throw between the title and editor.";
$(\'<p>\' + text_to_insert + \'</p>\').insertAfter(\'#titlediv\')
});
以下是在我自己的网站上使用该代码的结果:添加/编辑帖子屏幕的新挂钩:edit_form_after_title
add_action( \'edit_form_after_title\', \'myprefix_edit_form_after_title\' );
function myprefix_edit_form_after_title() {
echo \'<h2>This is edit_form_after_title!</h2>\';
}
对于有此问题的任何人,请查看以下帖子:More hooks on the edit screen 它允许通过新的本地Wordpress钩子插入自定义内容,这是一种更加稳定的解决方案。
我们添加了Custom Meta Box 在里面做我们的事。
有some hooks 那是not 元框,我们可以使用它将内容插入该管理页面:
add_action( \'edit_form_top\', function( $post )
{
echo \'<h1 style="color:red">edit_form_top</h1>\';
});
add_action( \'edit_form_after_title\', function( $post )
{
echo \'<h1 style="color:red">edit_form_after_title</h1>\';
});
add_action( \'edit_form_after_editor\', function( $post )
{
echo \'<h1 style="color:red">edit_form_after_editor</h1>\';
});
add_action( \'edit_page_form\', function( $post )
{
// edit_page_form is ONLY for pages, the other is for the rest of post types
echo \'<h1 style="color:red">edit_page_form/edit_form_advanced</h1>\';
});
add_action( \'dbx_post_sidebar\', function( $post )
{
echo \'<h1 style="color:red">dbx_post_sidebar</h1>\';
});
我想有一个元盒,让用户能够从下拉列表中选择一个网页从网站。我需要保存用户选择,以便以后使用。所以,我的问题是如何创建一个列出所有页面的元盒?