嗨,我创建了一个自定义帖子类型和自定义分类。自定义帖子类型页面名为 page-portfolio.php。我在其中创建了一个循环,我试图链接到每个帖子的单个页面。为此我创建了一个模板 single-portfolio.php 但由于某种原因,当我单击永久链接时,我会被发送到 404.php 页面。这是我的整个结构代码:
//custom post type and taxonomy declaration
<?php
add_action('init' , 'portfolio_manager');
function portfolio_manager(){
$args = array(
'label' => 'Portfolio Manager',
'singular_label' => 'Portfolio Manager',
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'supports' => array('title' , 'editor' , 'thumbnail'),
'rewrite' => array(
'slug' => 'portfolio',
'with_front' =>false
)
);
register_post_type('portfolio' , $args);
}
add_action('init' , 'portfolio_taxonomy');
function portfolio_taxonomy(){
register_taxonomy("portfolio-type",
array("portfolio"),
array("hierarchical" => true,
"label" => "Portfolio Types",
"singular_label" => "Portfolip Type",
"rewrite" => true,
"slug" => 'portfolio-type'
)
);
}
?>
//page-portfolio.php loop
$portfolio = new WP_Query(array(
'post_type'=>'portfolio',
'posts_per_page'=>'-1'
));
while($portfolio->have_posts()): $portfolio->the_post();
global $post;
?>
<li class ="item" data-type="<?php echo str_replace(" " , "" , strip_tags(get_the_term_list($post->ID, 'portfolio-type' , '' , '' , ''))); ?>" data-id="id-<?php the_ID(); ?>">
<span><a href="<?php the_permalink(); ?>">Details</a></span>
<?php
endif
?>
</li>
<?php
endwhile;
?>
如果 single-portfolio.php 不是我应该为此页面创建的页面模板,那么什么是 corect 模板?
如果 single-portfolio.php 是 corect 模板,那么我在这里做错了什么。为什么永久链接没有将我发送到 single.portfolio.php?