我在函数中定义了一个自定义的post类型电影。php
function create_post_type() {
register_post_type( \'movies\',
array(
\'supports\' => array(\'title\', \'editor\' , \'excerpt\' , \'custom-fields\'),
\'labels\' => array( \'taxonomies\' => \'mvgen\',
\'name\' => __( \'movies\' ),
\'singular_name\' => __( \'movies\' ),
),
\'public\' => true,
\'has_archive\' => true,
)
);
}
add_action( \'init\', \'create_post_type\' );
现在归档页和单页工作正常。但我为这种帖子类型定义了两种自定义分类法,例如“戏剧”和“摇滚”
我想当用户点击这个分类法时,他们会得到所有与这个特定分类法相关的帖子
为此,我创建了页面taxonomy-mvgen-drama.php
复制如下:
<?php get_header(); ?>
<section class="blog_sect">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php echo get_the_date(); ?>
<p>CATEGORY: <?php the_category(\', \'); ?></p>
</p>
<!-- ----------------printing taxonomy for a specifuic post------------------ -->
<?php
?>
<br>
<p><?php echo "LANGUAGES :"." ".get_the_term_list($post->ID, \'mvgen\', \'\' , \' , \') ?></p>
</b>
<?php endwhile; ?>
<?php endif; ?>
<?php get_footer(); ?>
</section>
<?php get_footer(); ?>
但每当我点击这个分类法时,它不会带我去分类法mvgen戏剧,而是带我去用url索引页面
http://localhost/movies/mvgen/rock/ 你能帮我做这个吗?
SO网友:MikeNGarrett
您还没有在这里发布注册分类法的代码,但我假设这是可行的。在创建自定义帖子类型的代码中,标签数组中包含分类法。这需要处于顶层。此外,分类法的值需要是一个数组,即使其中只有1项。见下文。More information.
function create_post_type() {
register_post_type( \'movies\',
array(
\'supports\' => array(\'title\', \'editor\' , \'excerpt\' , \'custom-fields\'),
\'taxonomies\' => array( \'mvgen\' ),
\'labels\' => array(
\'name\' => __( \'movies\' ),
\'singular_name\' => __( \'movies\' ),
),
\'public\' => true,
\'has_archive\' => true,
)
);
}
add_action( \'init\', \'create_post_type\' );
您的模板名称在我看来是正确的,但您始终可以引用
template hierarchy 以确保目标文件名正确。
此外,我发现Show Current Template plugin 在尝试确定正在使用的文件时提供帮助。