2015-10-28 34 views
0

WordPress是引发此错误消息:创建自定义后

警告:缺少论据2 _x(),称为“目录/ posttypes.php”上线8和“目录/本地化定义。上的PHP线250

postypes.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); 
} 

的functions.php:

include_once(ABSPATH . 'wp-content/themes/twentyeleven-child/posttypes.php'); 

l10n.php:

function _x($text, $context, $domain = 'default') { 
    return translate_with_gettext_context($text, $context, $domain); 
} 

任何建议将不胜感激,感谢

+0

为什么使用_x,如果你不提供上下文的getText?使用'__()'或'_e()'代替。 –

+0

@PaulSelitskas,你不希望使用'_e()'在这种情况下,因为我们只想'return'翻译串......不是'echo'它。 – rnevius

+1

@rnevius是你不会的!我只是指出'__()'/'_e()'和'_x()'/'_ex()'是不完全一样的。 –

回答

2

作为错误状态,则_x()函数有两个必要的参数:(1)文本的串是翻译,(2)翻译者的背景信息。

如果您不需要包括上下文,您可以使用__()。如果你不需要翻译字符串...不要使用任何一个函数。

以下任一将是有效的:

'label' => __('Recipes'), 
'singular_label' => __('Recipe'), 

或...

'label' => 'Recipes', 
'singular_label' => 'Recipe',