2010-09-07 68 views
0
$this->add_meta_box('select_post_template', __('Post Template', 'custom-post-templates'), 'select_post_template', 'post', 'side', 'default'); 

要使插件与自定义帖子类型一起工作,我被告知将“帖子”更改为自定义帖子类型的名称。有谁知道我是否可以通过改变这条线以某种方式使它与全部定制的帖子类型(包括常规帖子)一起工作?提前 http://wordpress.org/extend/plugins/custom-post-template/如何包含所有自定义帖子类型而不是仅帖子

感谢:

仅供参考,我发现这个在: http://wordpress.org/support/topic/custom-post-templates-with-custom-post-types-in-wp-30?replies=5#post-1679398

而且这是在参考了自定义帖子模板插件!

编辑:

我已经试过:

$post_types = get_post_types(array("public" => true)); 
foreach ($post_types as $post_type) { 
    $this->add_meta_box("select_post_template", __("Post Template", "custom-post-templates"), "select_post_template", $post_type, "side", "default"); 
} 

但自定义文章类型仍然没有得到模板选择菜单。这些帖子就像他们对原始代码所做的一样。感谢您的建议...有没有人有另一个?

注意:从概念上讲,该方法是可靠的。如果我使用自定义帖子类型的列表创建自己的数组,则此代码确实将模板添加到它们。

回答

1

您可以遍历所有已注册的帖子类型并为每个添加元框,但您可能需要过滤掉某些类型,因为附件也是帖子。

$post_types = get_post_types(array("public" => true)); 
foreach ($post_types as $post_type) { 
    add_meta_box("select_post_template", __("Post Template", "custom-post-templates"), "select_post_template", $post_type, "side", "default"); 
} 

具体就自定义帖子模板插件的问候,我认为这个问题是它的初始化后您的自定义文章类型注册(因为它不使用挂钩)。因此,$post_types(上面)不包含您的类型,并且不能为他们添加元框。你可以尝试加入这个技巧(在custom-post-templates.php末):

add_action('init', 'hack_add_meta_boxes'); 
function hack_add_meta_boxes() { 
    global $CustomPostTemplates; 
    $post_types = get_post_types(array('public' => true)); 
    foreach ($post_types as $post_type) { 
    $CustomPostTemplates->add_meta_box('select_post_template', __('Post Template', 'custom-post-templates'), 'select_post_template', $post_type, 'side', 'default'); 
    } 
} 
+0

感谢您尝试,但它并没有扩展到自定义文章类型:( – Matrym 2010-09-09 20:14:59

+0

我认为你的问题可能是您的自定义职位类型在自定义帖子模板插件被初始化之后被注册(因为它不使用钩子),所以'$ post_types'不包含你的帖子类型,并且不为它们添加元框。 – 2010-09-09 21:28:18

相关问题