最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Why is my taxonomy template not shown?

programmeradmin0浏览0评论

I have created a custom taxonomy for my site called projects with a matching template called taxonomy-projects.php. The problem is that when I browse to the template is not triggered, index.php is, but when I browse to the template shows up just fine.

How can have my template displayed when I browse to ?

Before you ask. Yes, I'm aware that I need to clear the rewrite rules before changes are made. I do this by saving the Permalink settings in the admin.

This is how I've created my custom taxonomy:

$args = array(
    'labels' => array(
        'name' => "Categories",
        'singular_name' => "Category",
        'search_items' => "Search Categories",
        'popular_items' => "Popular Categories",
        'all_items' => "All Categories",
        'parent_item' => "Parent Category",
        'parent_item_colon' => "Parent Category:",
        'edit_item' => "Edit Category",
        'update_item' => "Update Category",
        'add_new_item' => "Add New Category",
        'new_item_name' => "New Category Name",
    ),
    'hierarchical' => TRUE,
    'label' => 'Categories',
    'query_var' => TRUE,
    'rewrite' => array(
            'slug' => 'projects'
    ),
);

register_taxonomy('projects', 'project', $args);

UPDATE:

I've traced the output of $wp_query->get_queried_object() on each page and when I browse to a page with a term, such as I get the following output:

stdClass Object
(
    [term_id] => 4
    [name] => Commercial
    [slug] => commercial
    [term_group] => 0
    [term_taxonomy_id] => 8
    [taxonomy] => projects
    [description] => 
    [parent] => 0
    [count] => 1
)

However, when I browse to the output is nothing.

I'm failing to understand what I'm doing wrong. How can I make the taxonomy-projects.php shown when I browse to ?

I have created a custom taxonomy for my site called projects with a matching template called taxonomy-projects.php. The problem is that when I browse to http://mysite/projects the template is not triggered, index.php is, but when I browse to http://mysite/projects/someterm the template shows up just fine.

How can have my template displayed when I browse to http://mysite/projects?

Before you ask. Yes, I'm aware that I need to clear the rewrite rules before changes are made. I do this by saving the Permalink settings in the admin.

This is how I've created my custom taxonomy:

$args = array(
    'labels' => array(
        'name' => "Categories",
        'singular_name' => "Category",
        'search_items' => "Search Categories",
        'popular_items' => "Popular Categories",
        'all_items' => "All Categories",
        'parent_item' => "Parent Category",
        'parent_item_colon' => "Parent Category:",
        'edit_item' => "Edit Category",
        'update_item' => "Update Category",
        'add_new_item' => "Add New Category",
        'new_item_name' => "New Category Name",
    ),
    'hierarchical' => TRUE,
    'label' => 'Categories',
    'query_var' => TRUE,
    'rewrite' => array(
            'slug' => 'projects'
    ),
);

register_taxonomy('projects', 'project', $args);

UPDATE:

I've traced the output of $wp_query->get_queried_object() on each page and when I browse to a page with a term, such as http://mysite/projects/commercial I get the following output:

stdClass Object
(
    [term_id] => 4
    [name] => Commercial
    [slug] => commercial
    [term_group] => 0
    [term_taxonomy_id] => 8
    [taxonomy] => projects
    [description] => 
    [parent] => 0
    [count] => 1
)

However, when I browse to http://mysite/projects the output is nothing.

I'm failing to understand what I'm doing wrong. How can I make the taxonomy-projects.php shown when I browse to http://mysite/projects?

Share Improve this question edited Jul 22, 2011 at 0:12 Luke asked Jul 20, 2011 at 22:18 LukeLuke 5912 gold badges9 silver badges21 bronze badges 1
  • I had similar problem and was solved when I visited the permalinks settings page in wordpress admin. ( just visited the page, nothing else ! ) – ankittiwaari Commented May 8, 2014 at 8:29
Add a comment  | 

3 Answers 3

Reset to default 1

you have to use archive-projects.php to work mysite/projects, that's all

Have you tried it with the permalink base in the url? It defaults to "category". http://mysite/category/projects The WP codex is quoted below.

'with_front' - allowing permalinks to be prepended with front base - defaults to true

You would need to set 'with_front' to false for http://mysite/projects to work.

Also when you have only 'projects' in your url it is hard for WP to know if it is a post, page, custom post type, taxonomy, etc.

Did you flush the rewrite rules? Add this after your custom taxonomy code:

    flush_rewrite_rules();

You only need to have this run once when you make a change. Comment it out after it works.

发布评论

评论列表(0)

  1. 暂无评论