自定义帖子类型永久链接发送到404.php

时间:2012-08-20 09:37:18

标签: wordpress

您好我已经创建了自定义帖子类型和自定义分类。自定义帖子类型页面被命名为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是核心模板,那么我在这里做错了什么。为什么固定链接没有把我发送到single.portfolio.php?

1 个答案:

答案 0 :(得分:0)

尝试将其重命名为single-portfolio.php

在此处详细了解:http://codex.wordpress.org/Template_Hierarchy

一切顺利, 貂