我正在使用Metabox 为Worpdress Post创建元数据库,它就像一个符咒。现在我已安装MetaBox Custom Post Type Extension 对于创建CPT,它可以很好地工作。我有Types 插件安装的目的相同,创建CPT以便我可以使用Metabox或类型。我用slug创建了一个CPTpublicity
我只想在CPT中添加一些元盒。我如何才能做到这一点?我知道如何使用插件创建元盒,我只是不知道如何在Wordpress帖子和这种自定义帖子类型之间做出区别,也许可以通过在functions.php
检查post类型slug,然后包括所需的文件,但不确定,我需要一些推送,有什么建议吗?
基于自定义帖子类型创建元对象
2 个回复
最合适的回答,由SO网友:fischi 整理而成
在注册元盒之前定义元盒时,只需设置其适用的PostType:
$f711_meta_boxes[] = array(
\'id\' => \'details\',
\'title\' => __( \'Details\', \'f711_theme\' ),
\'pages\' => array( \'publicity\' ), // change this values
\'context\' => \'normal\',
\'priority\' => \'high\',
\'fields\' => array(
array(
\'name\' => __( \'Fischi ist\', \'f711_theme\' ),
\'desc\' => __( \'Jaja, Beschreibung\', \'f711_theme\' ),
\'id\' => \'f711_is\',
\'type\' => \'select\',
\'options\' => array( __( \'gut\', \'f711_theme\' ), __( \'super\', \'f711_theme\' ))
)
)
);
SO网友:tao
if ( \'your_cpt\' == get_post_type()) { ... }
或if (is_singular( array(\'your_cpt\'))) { ... }
is_singular()
仅当在单个贴子页上时才为真。如果您在存档页上,则需要is_post_type_archive(\'your_cpt\') { ... }
以下是有用的WP Conditional tags.