个性化阅读
专注于IT技术分析

WordPress:is_single不适用于帖子类型

点击下载

WordPress:is_single不适用于帖子类型

大家好,

Ive有一个标准的博客模板, 该模板除了使用标准的博客外, 还使用帖子类型:画廊, 视频, 音频和报价。我有一个content.php, 它通常指示每种类型的处理。对于单个帖子显示, 我有一个模板部件加载, 可以处理我认为所有单个帖子的内容, 但实际上仅适用于标准单个帖子, 并且不包括单个画廊, 视频, 音频和报价帖子。 (内容单一模板分配了”相关帖子”功能, 而其他功能则未显示在博客帖子列表中, 无论哪种类型, 我都希望在所有单个帖子上可见该模板)

除了标准的is_single())外, 我还尝试过is_single(‘post types’))和is_singular(array(‘post_type1’等)); …

我已经浏览了法典(http://codex.wordpress.org/Conditional_Tags#A_Single_Post_Page), 并且看到了有关如何将不同模板分配给不同帖子类型(例如http://gabrieleromanato.name/wordpress)的博客文章。为每个帖子格式创建一个不同的PHP模板, 但我相反:我希望is_single适用于所有帖子类型:标准, 视频, 音频, 图库和报价。我尝试了这里建议的方法Wordpress Conditional if_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(); ?>

#1


因为帖子类型不是is_single()-is_singular()你可以在此处了解更多信息


#2


对于自定义帖子类型, 请使用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(); ?>
赞(0)
未经允许不得转载:srcmini » WordPress:is_single不适用于帖子类型

评论 抢沙发

评论前必须登录!