我想添加新的帖子类型
我有一个php文件(posttype.php),位于:wordpress/wp-content/themes/
代码如下:
<?php
// Add new post type for Recipes
add_action(\'init\', \'cooking_recipes_init\');
function cooking_recipes_init()
{
$args = array(
\'label\' => _x(\'Recipes\'),
\'singular_label\' => _x(\'Recipe\'),
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'menu_position\' => null,
\'supports\' => array(\'title\',\'editor\',\'comments\')
);
register_post_type(\'recipes\',$args);
}
?>
我在页面顶部遇到了一个问题(但posttype是suc创建的):
Warning: Missing argument 2 for _x(), called in D:\\xampp\\htdocs\\wordpress\\wp-content\\themes\\posttypes.php on line 12 and defined in D:\\xampp\\htdocs\\wordpress\\wp-includes\\l10n.php on line 189
Warning: Missing argument 2 for _x(), called in D:\\xampp\\htdocs\\wordpress\\wp-content\\themes\\posttypes.php on line 14 and defined in D:\\xampp\\htdocs\\wordpress\\wp-includes\\l10n.php on line 189
谢谢你。
SO网友:wpmemorize
标签需要两个必要的参数,即$text和$context。
这是您的代码,其中包含一个参数$text,您需要添加第二个参数。
$args = array(
\'label\' => _x(\'Recipes\'),
\'singular_label\' => _x(\'Recipe\'),
包含两个参数的代码如下所示。
$args = array(
\'label\' => _x(\'Recipe\', \'post type general name\'),
\'singular_label\' => _x(\'Recipe\', \'post type general name\'),
有关自定义帖子类型的详细说明,请访问
here