【问题标题】:Conditional Tags for Custom Post Types自定义帖子类型的条件标签
【发布时间】:2018-04-20 00:31:34
【问题描述】:

我刚刚开始为我的网站使用自定义帖子类型,并在此自定义帖子类型中的某些页面上使用,例如:

/custom/post-one /custom/后三

我想在标题中显示一些不同的内容。这对于以下页面很容易做到:

if (is_page(array('page-here','page-here','page-here','page-here'))) {
include(TEMPLATEPATH.'/header-red.php');
} 
elseif (is_page(array('page-here','page-here','page-here','page-here'))) {
include(TEMPLATEPATH.'/header-blue.php');
}
elseif (is_page(array('page-here'))) {
include(TEMPLATEPATH.'/header-green.php');
}  
else {
get_header();
}

我将如何转换我用于普通页面的上述脚本,以在我的自定义帖子类型页面上工作?

【问题讨论】:

    标签: php html wordpress custom-wordpress-pages


    【解决方案1】:

    你需要在headr.php中使用这种类型的代码

    if(is_singular( 'postType' )){
        //code which you want to render for this perticular post type   
    }else{
    
        //your defalult code
    }
    

    在此代码中,postType 是您的帖子类型名称。

    【讨论】:

    • 谢谢,所以我会放什么而不是 postType?帖子标题还是蛞蝓?
    • 您需要输入您注册帖子类型的帖子类型名称。
    • 问题是我想定位自定义帖子类型中的单个帖子,而不是帖子类型中的所有帖子 - 这有意义吗?
    【解决方案2】:

    我现在通过使用 Post ID 实现了这一点,如下所示:

    if ( get_the_ID() == 4915 ) {
    include(TEMPLATEPATH.'/header-red.php');
    } 
    elseif ( get_the_ID() == 7564 ) {
    include(TEMPLATEPATH.'/header-blue.php');
    }
    elseif ( get_the_ID() == 71564 ) {
    include(TEMPLATEPATH.'/header-green.php');
    }  
    else {
    get_header();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-06
      • 2012-11-01
      • 2012-05-01
      • 2023-04-04
      • 1970-01-01
      相关资源
      最近更新 更多