Wordpress:is_single不适用于帖子类型

时间:2014-10-31 05:52:12

标签: php wordpress wordpress-theming

Wordpress:is_single不适用于帖子类型

大家好,

除了标准之外,我还有一个使用帖子类型的标准博客模板:图库,视频,音频和报价。我有一个content.php来指导每种类型的处理。对于单个帖子显示,我有一个模板部分加载应该处理我认为所有单个帖子,但实际上只适用于标准单个帖子,不包括单个画廊,视频,音频和报价帖子。 (内容单一模板分配了一个"相关帖子"功能以及其他不会显示在博客帖子列表中的内容,我想要在所有单个帖子上显示,无论其类型如何)

除了标准的is_single())之外,我还尝试了is_single('帖子类型'))和is_singular(数组(' post_type1'等)); ......

我已经通过了手抄本(http://codex.wordpress.org/Conditional_Tags#A_Single_Post_Page),并且我看过有关如何将不同模板分配到不同帖子类型的博客文章,例如http://gabrieleromanato.name/wordpress-create-a-different-single-php-template-for-each-post-format/,但是我&#39 ;相反:我希望is_single适用于所有帖子类型:标准,视频,音频,图库和报价。我尝试了这里建议的方法Wordpress Conditional if is_single关于为每个帖子类型创建单独的模板部分(通过制作内容的副本 - 单个命名的单视频,单音频等),但这也没有用。

我知道我是愚蠢的。提前感谢您提出的任何建议。

<?php elseif (is_single( ) ) : ?>
<?php get_template_part( 'content-single'); ?>

<?php else : ?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <header class="entry-header">
    <div id="entry-category"><?php the_category(', '); ?></div>
    <div id="entry-title"><?php the_title( sprintf( '<h1><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h1>' ); ?></div><!--- .entry-title -->
<div id="entry-date"><?php the_time('l, jS F Y');?></div><!-- .entry-meta -->

    </header><!-- .entry-header -->

    <div class="entry-content">
        <div class="post-header">

    <?php if ( has_post_thumbnail() ) {
        the_post_thumbnail();
        }
        the_content(); ?>

2 个答案:

答案 0 :(得分:1)

因为帖子类型不是is_single() - 它是is_singular() 您可以阅读有关HERE

的更多信息

答案 1 :(得分:0)

自定义帖子类型使用is_singular()

<?php elseif (is_singular('your_post_type_name') ) : ?>
<?php get_template_part( 'content-single'); ?>

<?php else : ?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <header class="entry-header">
    <div id="entry-category"><?php the_category(', '); ?></div>
    <div id="entry-title"><?php the_title( sprintf( '<h1><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h1>' ); ?></div><!--- .entry-title -->
<div id="entry-date"><?php the_time('l, jS F Y');?></div><!-- .entry-meta -->

    </header><!-- .entry-header -->

    <div class="entry-content">
        <div class="post-header">

    <?php if ( has_post_thumbnail() ) {
        the_post_thumbnail();
        }
        the_content(); ?>