【发布时间】:2016-08-18 23:30:14
【问题描述】:
基本上,我的网站是基于一个缺少大量代码的主题构建的,而这些代码应该存在。我已经设法解决了除此之外的所有问题。
该网站具有投资组合帖子类型。基本上正在创建类别,并且可以将帖子分配给这些类别。帖子已创建,但类别的存档页面返回“找不到页面”。
我的functions.php部分如下:
/** taxonomy.
--------------------------------------------------------------------------------------------------- */
function create_portfolio_taxonomy()
{
register_taxonomy(
'portfolio-category',
'portfolio',
array(
'labels' => array(
'name' => _x('Categories', 'portfolio', 'awe'),
'singular_name' => _x('Category', 'portfolio', 'awe'),
'menu_name' => __('Categories', 'awe'),
'all_items' => __('All Categories', 'awe'),
'edit_item' => __('Edit Category', 'awe'),
'view_item' => __('View Category', 'awe'),
'update_item' => __('Update Category', 'awe'),
'add_new_item' => __('Add New Category', 'awe'),
'new_item_name' => __('New Category Name', 'awe'),
'parent_item' => __('Parent Category', 'awe'),
'parent_item_colon' => __('Parent Category:', 'awe'),
'search_items' => __('Search Categories', 'awe'),
),
'show_admin_column' => true,
'hierarchical' => true,
'rewrite' => array(
'slug' => 'category',
),
)
);
}
add_action('init', 'create_portfolio_taxonomy', 0);
add_action('init', 'custom_taxonomy_flush_rewrite');
function custom_taxonomy_flush_rewrite() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
/*------------------------------------------------------------------------------------------------------------------*/
/* custom post type
/*------------------------------------------------------------------------------------------------------------------*/
add_action( 'init', 'create_portfolio_post_type' );
function create_portfolio_post_type() {
register_post_type( 'portfolio',
array(
'labels' => array(
'name' => __( 'Portfolio' ),
'singular_name' => __( 'Portfolio' )
),
'menu_icon' => 'dashicons-portfolio',
'hierarchical' => 'true',
'public' => true,
'has_archive' => true,
)
);
}
如您所见,我可以通过主页上的投资组合部分的类别进行排序 - willd.co.uk/#clients
帖子页面 - http://willd.co.uk/portfolio/victoria-front-of-house/ 无法使用的类别页面 - http://willd.co.uk/category/eggs/
从我收集到的 Wordpress 经历了潜在模板的层次结构,然后将来到 archive.php
我是 php 新手,所以真的只是使用教程和逻辑来让一切正常工作。
我已经刷新了永久链接。
我在想也许我需要创建和编辑一个portfolio-archive.php 或taxonomy.php 文件,而不是让它落入archive.php,尽管我看过教程和其他stackoverflow 答案我还没有解决这个问题。
非常感谢您的帮助,
W
【问题讨论】:
-
WordPress 默认博客类别具有“类别”的名称,因此最好将其命名为其他名称,因为它可能会试图覆盖它。还可以尝试创建 taxonomy-category.php 文件并在主题根目录中使用存档页面的内容填充它
-
谢谢你,理查德 - 我认为蛞蝓正在覆盖它!
标签: php wordpress wordpress-theming taxonomy custom-taxonomy