【发布时间】:2016-01-09 17:44:29
【问题描述】:
这里有个小问题。到目前为止,我有两个帖子类别:category_name=projects 和 category_name=blog。所以我希望每个类别的帖子有不同的风格和不同的输出。 所以我创建了两个文件projects.php和content.php,然后我把下面的代码放在single.php中
<?php get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if ( 'category_name=projects' ) : ?>
<?php get_template_part( 'template-parts/project', get_post_format() );
the_post_navigation();
?>
<?php else : ?>
<?php get_template_part( 'template-parts/content', get_post_format() );
the_post_navigation();
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
<?php endif; ?>
<?php endwhile; else : ?>
<p>
<?php _e( 'Sorry, no posts matched your criteria.' ); ?>
</p>
<?php endif; ?>
</main>
<!-- #main -->
</div>
<!-- #primary -->
<?php
get_sidebar(); get_footer();
一切正常,但当我开始编辑项目和单个 php 时,它并没有区分类别。 以下代码来自projects.php
<article id="post-<?php the_ID(); ?>" <?php post_class( ''); ?>>
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );?>
<header class="entry-header project-header" style="background-image: url('<?php echo $thumb['0'];?>'); height: 80vh;
background-size: cover; background-repeat: no-repeat; background-position: center;">
</header>
<div class="entry-content">
<section class="quater">
<div class="container-fluid">
<h2><?php the_title(); ?></h2>
<h3>Published: <?php the_time('jS F Y') ?></h3>
</div>
</section>
<section class="project-content">
<?php the_content () ?>
</section>
</div>
<footer class="entry-footer">
<?php fish_entry_footer(); ?>
</footer>
</article>
所以问题是 - 我如何为每个文件引用特定类别?
【问题讨论】: