自定义邮政类型“;“单一”;don';不要在wordpress中显示我的代码

自定义邮政类型“;“单一”;don';不要在wordpress中显示我的代码,wordpress,post,Wordpress,Post,我正在尝试使用以下方式在服装贴子类型“single”中显示我的代码: 但是没有什么是有效的是单数的,接受的参数是post\u类型。is_object_in_term是一个条件函数,用于检查给定对象(post)是否在分类术语(category,tag)内。那么代码呢- add_filter( 'the_content', 'wpse_the_content' ); function wpse_the_content( $content ) { if( is_singular('portfo

我正在尝试使用以下方式在服装贴子类型“single”中显示我的代码:


但是没有什么是有效的

是单数的,接受的参数是
post\u类型
。is_object_in_term是一个条件函数,用于检查给定对象(post)是否在分类术语(category,tag)内。那么代码呢-

add_filter( 'the_content', 'wpse_the_content' );
function wpse_the_content( $content )
{
    if( is_singular('portfolio') )
    {
        $content .= '<p>the Book post type exists</p>';
    }
    return $content;
}
add_filter('the_content','wpse_the_content');
函数wpse__内容($content)
{
如果(是单数(‘投资组合’)
{
$content.='存在书后类型

'; } 返回$content; }

您的自定义帖子类型
公文包
应该已经在分类法-
类别
中注册。或者,如果是自定义分类法,请将
is\u object\u in_term
函数中的第二个参数替换为该参数。

这是否意味着-当文本位于
portfolio
类别中时,您希望在单个post类型页面
portfolio
上显示文本?是的。那正是我想要的。这对我不起作用。我看不出有什么变化。我将代码放在functions.php中。看这里:我的答案是基于你的问题。然而,我发现了两个问题。1.您提供的链接帖子未分配名为“portfolio”的类别,2。我提供的代码应该放在
single.php
single portfolio.php
,而不是
functions.php
。谢谢。我正在构建一个插件,我希望它能够自动工作,而不改变主题文件。2) 你说的不是“投资组合”是什么意思?。。。请解释一下,非常感谢你,但这对我还是不起作用。我想我可能在下面用了一个错误的短语:if(is_singular('portfolio'))。服装贴类型类别名称为公文包。请参阅:函数portfolio_register(){$labels=array('name'=>x('portfolio','post-type-general-name'),
if ( is_singular()
add_filter( 'the_content', 'wpse_the_content' );
function wpse_the_content( $content )
{
    if( is_singular('portfolio') )
    {
        $content .= '<p>the Book post type exists</p>';
    }
    return $content;
}