无法查看CPT存档模板

时间:2017-01-23 作者:Benn

我不确定我在这里遗漏了什么,cpt存档页面根本不想显示。我重置永久链接(默认情况下为currenlty),复制archive.php 并重命名为archive-articles.php (测试了我能想到的任何东西)但是custom template 不想显示。It加载default archive.php、 2017年测试。这个single-article.php 现成的,但不是存档的。

/****************************************
 * Add custom taxonomy for Articles *
 ****************************************/

add_action(\'init\', \'articles_categories_register\');

function articles_categories_register() {
$labels = array(
    \'name\'                          => \'Articles Categories\',
    \'singular_name\'                 => \'Articles Category\',
    \'search_items\'                  => \'Search Articles Categories\',
    \'popular_items\'                 => \'Popular Articles Categories\',
    \'all_items\'                     => \'All Articles Categories\',
    \'parent_item\'                   => \'Parent Article Category\',
    \'edit_item\'                     => \'Edit Article Category\',
    \'update_item\'                   => \'Update Article Category\',
    \'add_new_item\'                  => \'Add New Article Category\',
    \'new_item_name\'                 => \'New Article Category\',
    \'separate_items_with_commas\'    => \'Separate articles categories with commas\',
    \'add_or_remove_items\'           => \'Add or remove articles categories\',
    \'choose_from_most_used\'         => \'Choose from most used articles categories\'
    );

$args = array(
    \'label\'                         => \'Articles Categories\',
    \'labels\'                        => $labels,
    \'public\'                        => true,
    \'hierarchical\'                  => true,
    \'show_ui\'                       => true,
    \'show_in_nav_menus\'             => true,
    \'args\'                          => array( \'orderby\' => \'term_order\' ),
    \'rewrite\'                       => array( \'slug\' => \'articles\', \'with_front\' => true, \'hierarchical\' => true ),
    \'query_var\'                     => true
);

register_taxonomy( \'articles_categories\', \'articles\', $args );
}

/*****************************************
 * Add custom post type for Articles *
 *****************************************/

add_action(\'init\', \'articles_register\');

function articles_register() {

    $labels = array(
        \'name\' => \'Articles\',
        \'singular_name\' => \'Article\',
        \'add_new\' => \'Add New\',
        \'add_new_item\' => \'Add New Article\',
        \'edit_item\' => \'Edit Article\',
        \'new_item\' => \'New Article\',
        \'view_item\' => \'View Article\',
        \'search_items\' => \'Search Articles\',
        \'not_found\' =>  \'Nothing found\',
        \'not_found_in_trash\' => \'Nothing found in Trash\',
        \'parent_item_colon\' => \'\'
    );

    $args = array(
        \'labels\' => $labels,
        \'public\' => true,
        \'publicly_queryable\' => true,
        \'show_ui\' => true,
        \'query_var\' => true,
        \'has_archive\' => true,
        \'rewrite\' => array( \'slug\' => \'articles\', \'with_front\' => true ),
        \'capability_type\' => \'post\',
        \'menu_position\' => 6,
        \'supports\' => array(\'title\', \'excerpt\', \'editor\',\'thumbnail\') //here you can specify what type of inputs will be accessible in the admin area
      );

    register_post_type( \'articles\' , $args );
}

1 个回复
最合适的回答,由SO网友:rudtek 整理而成

我的系统设置与上面的代码完全相同。我得到了同样的结果。我所做的是改变你的路线

    \'rewrite\' => array( \'slug\' => \'articles\', \'with_front\' => true ),

    \'rewrite\' => array( \'slug\' => \'articles2\', \'with_front\' => true ),
然后到

    \'rewrite\' => array( \'slug\' => \'articlis\', \'with_front\' => true ),
在最后两个选项中,一切都很顺利。看起来可能已经有了文章的内置用法,所以当你写“文章”时,wordpress不知道该怎么做。我没有解释。

我仍然建议使用比您当前使用的更具体的CPT名称。

你能用一个真正代表文章的名字来代替文章吗?正在更改

相关推荐