[英]Custom Post Type Archive Template
I'm trying to set up a custom archive template for a custom post type I created in functions.php. 我正在尝试为我在functions.php中创建的自定义帖子类型设置自定义存档模板。 Here is the code in functions:
这是函数中的代码:
add_action('init', 'create_post_type');
function create_post_type() {
$labels = array(
'name' => __('Portfolio Posts'),
'singular_name' => __('Portfolio Post')
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'rewrite' => false,
'supports' => array('title', 'editor', 'excerpt'),
'taxonomies' => array('category'),
);
register_post_type('cc-portfolio', $args);
}
I've also created my archive-cc-portfolio.php file. 我还创建了archive-cc-portfolio.php文件。
The problem is, when I access the site http://site.com/cc-portfolio/ I get the default index.php file used as the template. 问题是,当我访问站点http://site.com/cc-portfolio/时,我将默认的index.php文件用作模板。
Any ideas what I am doing wrong or where to start looking? 有任何想法我做错了什么或从哪里开始寻找?
Thanks, 谢谢,
Phil 菲尔
Your archive page template will only show when you view a piece of content. 仅当您查看内容时,才会显示存档页面模板。
If you add content with title "abcd" and assuming you have permalinks as "%postname%", the you would access that content as 如果添加标题为“ abcd”的内容,并假设永久链接为“%postname%”,则您将以以下方式访问该内容
http://site.com/cc-portfolio/abcd . http://site.com/cc-portfolio/abcd 。
I also believe that you need to name your template single-cc-portfolio.php 我也认为您需要将模板命名为single-cc-portfolio.php
Have a look at the following plugin 看看下面的插件
http://wordpress.org/extend/plugins/custom-content-type-manager/ http://wordpress.org/extend/plugins/custom-content-type-manager/
Try and play with that, and you'll probably see where you're going wrong :) 尝试并尝试,您可能会发现哪里出了问题:)
Thanks 谢谢
Blake 布莱克
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.