帮助警告创建新的帖子类型?

时间:2011-10-14 作者:Gore

在创建自定义帖子类型时,我收到了几个警告,有人建议我使用插件,但由于我是新手,我想知道发生了什么,所以我想手动执行。这是我收到的警告。

Warning: Missing argument 2 for _x(), called in C:\\xampp\\htdocs\\wordpress\\wp-content\\themes\\posttypes.php on line 8 and defined in C:\\xampp\\htdocs\\wordpress\\wp-includes\\l10n.php on line 189

Warning: Missing argument 2 for _x(), called in C:\\xampp\\htdocs\\wordpress\\wp-content\\themes\\posttypes.php on line 9 and defined in C:\\xampp\\htdocs\\wordpress\\wp-includes\\l10n.php on line 189

Warning: Missing argument 2 for _x(), called in C:\\xampp\\htdocs\\wordpress\\wp-content\\themes\\posttypes.php on line 28 and defined in C:\\xampp\\htdocs\\wordpress\\wp-includes\\l10n.php on line 189

Warning: Missing argument 2 for _x(), called in C:\\xampp\\htdocs\\wordpress\\wp-content\\themes\\posttypes.php on line 29 and defined in C:\\xampp\\htdocs\\wordpress\\wp-includes\\l10n.php on line 189

Warning: Missing argument 2 for _x(), called in C:\\xampp\\htdocs\\wordpress\\wp-content\\themes\\posttypes.php on line 48 and defined in C:\\xampp\\htdocs\\wordpress\\wp-includes\\l10n.php on line 189

Warning: Missing argument 2 for _x(), called in C:\\xampp\\htdocs\\wordpress\\wp-content\\themes\\posttypes.php on line 49 and defined in C:\\xampp\\htdocs\\wordpress\\wp-includes\\l10n.php on line 189
这是我的密码

<?php 

//Add new post type for Models
add_action(\'init\', \'models_portfolio_init\');
function models_portfolio_init()
{
    $args = array(
                    \'label\' => _x(\'Models\'),
                    \'singular_label\' => _x(\'Models\'),
                    \'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);
}

//Add new post type for Books
add_action(\'init\', \'books_posts_init\');
function books_posts_init()
{
    $args = array(
                    \'label\' => _x(\'Books\'),
                    \'singular_label\' => _x(\'Books\'),
                    \'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(\'books\',$args);
}

//Add new post type for Advertisements
add_action(\'init\', \'advertisements_init\');
function advertisements_init()
{
    $args = array(
                    \'label\' => _x(\'Advertisements\'),
                    \'singular_label\' => _x(\'Advertisements\'),
                    \'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(\'advertisements\',$args);
}

?>

2 个回复
最合适的回答,由SO网友:Rutwick Gangurde 整理而成

无论你在哪里使用_x(\'lorem\'), 使用_x(\'lorem\', \'models\'); 相反模型实际上应该是一个上下文,但我不知道您的上下文,因此使用模型。试试这个。

SO网友:Ian Scott Armstrong

我正试图把这篇文章放到一些搜索排名靠前的地方。

根据OP发布的代码,他正在通过Lynda工作。自定义帖子类型的com教程。我已经做了一个,它在最新版本的WordPress中确实有一个小故障,但这不是WP的错。

如果后续的求助者找到此帖子,他们需要等待下一章:

$args = array(
    \'label\' => _x(\'Foos\')
    \'singular_label\' => _x(\'Foo\')
成为:

$args = array(
    \'label\' => _x(\'Foos\', \'post type general name\'),
    \'singular_label\' => _x(\'Foo\', \'post type singular name\')
此时第二个参数确实存在,错误消息消失。

OP也在呼叫:

    register_post_type(\'recipes\',$args);
而不是他的新model\\u types定义,这是因为Lynda教程基于厨师的自定义组合。

在产生错误的第一章中,学生可以使用以下版本来消除问题(删除x,删除第二个参数):

    $args = array(
        \'label\' => __(\'Foos\')
        \'singular_label\' => __(\'Foo\')
通过简单地消除参数调用,它们会使标签的自定义描述无效,因此应该在最终版本中替换它。实际上,本教程将让您删除原始定义,因为它们稍后将由数组处理。

因此,只需将x更改为(然后继续)。

无论如何,我真的希望这能帮助未来受挫的学生。

结束

相关推荐

Query not returning CPT posts

哎哟,我的头撞到墙上了!我正在尝试在索引中查询我的帖子类型“clips”。php,但它只返回默认“post”中的post。我需要一些洞察力!我做错了什么?我的帖子类型:$args = array( \'labels\' => $labels, \'supports\' => $supports, \'hierarchical\' => false, \'menu_position\' => 4, \