我想将元盒制作为固定元素,删除扩展功能和拖放功能。
有什么想法吗?
我想将元盒制作为固定元素,删除扩展功能和拖放功能。
有什么想法吗?
取消邮箱脚本的注册似乎有点过激,如前所述,permalink slug的“编辑”按钮不再像预期的那样工作。
实际上,我想出了另一种方法,它使用Wordpress的过滤器和jQuery UI可排序插件的功能,允许在从特定元素通过cancel 选项
a(".meta-box-sortables").sortable({
...
connectWith: ".meta-box-sortables",
items: ".postbox",
handle: ".hndle",
...
});
因此插件为元素创建了一个可排序的列表.postbox
. 排序与子元素一起发出.hndle
.Adding classes to the .postbox
elements
postbox_classes_{page}_{id}
{page}
是metabox显示的页面{id}
是元盒id因此,如果我将id为“\\u movie\\u details\\u metabox”的metabox应用于名为“movie\\u type”的自定义帖子类型,则可以执行以下操作:
function metabox_not_sortable($classes) {
$classes[] = \'not-sortable\';
return $classes;
}
add_filter(\'postbox_classes_movie_type__movie_details_metabox\', \'metabox_not_sortable\');
Alter jquery ui sortable instance
然后,您可以在管理区域中插入页脚脚本,以更改可排序实例以取消排序事件(如果它是通过.hndle
添加了css类的邮箱中的元素not-sortable
: <?php
add_action(\'admin_print_footer_scripts\',\'my_admin_print_footer_scripts\',99);
function my_admin_print_footer_scripts()
{
?><script type="text/javascript">/* <![CDATA[ */
jQuery(function($)
{
$(".meta-box-sortables")
// define the cancel option of sortable to ignore sortable element
// for boxes with \'.not-sortable\' css class
.sortable(\'option\', \'cancel\', \'.not-sortable .hndle, :input, button\')
// and then refresh the instance
.sortable(\'refresh\');
});
/* ]]> */</script><?php
}
带有css类的邮箱.not-sortable
不能再排序了,其他的仍然可以。deregister “邮箱”脚本。在主题中放置以下内容functions.php
或者在插件文件中。
function dereg() {
wp_deregister_script(\'postbox\');
}
add_action(\'admin_init\',\'dereg\');
我做了一个非常粗略的测试,它确实停止了拖拽和折叠,我没有发现任何损坏。小折叠箭头仍会显示,但这是CSS而不是Javascript。如果它困扰着你,你可以用:
function acss() {
echo \'<style type="text/css">.postbox:hover .handlediv,
.stuffbox:hover .handlediv {display: none;
}</script>\';
}
add_action(\'admin_head\',\'acss\');
回答一半的问题,以下是如何在自定义帖子类型中删除折叠:
php for including css for post.php edit page
function enqueue_your_custom_adminstuff(){
wp_enqueue_style(\'mycustomstyle\', plugins_url(\'/css/mycustomstyle.css\', __FILE__),array(),filemtime(plugin_dir_path( __FILE__ )."/css/mycustomstyle.css"));
/* Note: I use filemtime to prevent caching the old style version */
}
add_action(\'admin_enqueue_scripts\', \'enqueue_your_custom_adminstuff\');
mycustomstyle.css
.post-type-yourcustomposttypeslug .postbox.closed .handlediv .toggle-indicator:before{
content: "\\f142"!important; /* the arrow */
}
.post-type-yourcustomposttypeslug .postbox.closed .inside{
display:block;
}
我正在寻找一些关于如何创建一个允许用户从链接类别列表中选择的元框的建议或教程链接。到目前为止我一直在看this post about taxonomies in a drop down 和this post about an audio file drop down. 我也看过get_terms. 最终目标是在单个帖子页面上显示用户选择的链接类别中的链接。更新#2。现在让它正常工作(更新代码)。最后一件事:我只需要找到一种方法来保持选中的选项处于选中状态。它保存了正确的值,但在视觉上只是默认为第一个选项。