Wordpress自定义文章类型档案未加载


Wordpress Custom Post Type Archive Not Loading

我在WordPress 3.7.1中设置了一个自定义的"游戏"帖子类型。一切都很好,我已经创建了几个这种帖子类型的项目,并为它们创建/分配了类别。显示来自这个CPT的帖子的查询正常工作,我的自定义单页(singlegame.php)也正常工作。

然而,当我创建archive-game.php时,WordPress加载默认的archive.php文件,并且分页不起作用。我搜索了几个小时,尝试了一些解决方案,但都无济于事。我正试图获得我在CPT下创建的每个类别的档案,我做得对吗?WordPress的最新版本是否发生了可能影响这一点的变化?

这是我创建自定义帖子类型的代码:

public function gv_game_setup_post_types() {
    $game_labels = array(
        'name'                => 'Games',
        'singular_name'       => 'Game',
        'add_new'             => __('Add New', 'game'),
        'add_new_item'        => __('Add New Game', 'game'),
        'edit_item'           => __('Edit Game', 'game'),
        'new_item'            => __('New Game', 'game'),
        'all_items'           => __('All Games', 'game'),
        'view_item'           => __('View Game', 'game'),
        'search_items'        => __('Search Games', 'game'),
        'not_found'           => __('No Games found', 'game'),
        'not_found_in_trash'  => __('No Games found in Trash', 'game'),
        'parent_item_colon'   => '',
        'menu_name'           => __('Games', 'game'),
        'exclude_from_search' => false
    );
    $game_args = array(
        'labels'              => $game_labels,
        'public'              => true,
        'has_archive'         => true,
        'publicly_queryable'  => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'query_var'           => true,
        'capability_type'     => 'post',
        'hierarchical'        => false,
        'supports'            => array('editor', 'title', 'thumbnail', 'custom-fields'),
        'taxonomies'          => array('category', 'post_tag'),
        'rewrite'             => array('slug' => 'game', 'with_front' => false)
    );
    register_post_type('game', $game_args);
}

这个函数是我为此目的制作的自定义插件的一部分,并且在"init"钩子上的构造函数中被调用。

感谢您的帮助。

谢谢!

我使用这个插件来创建我的自定义帖子类型,一旦它启动并工作,就可以选择导出php代码,然后将其添加到函数文件中,然后禁用该插件。对我来说,这是确保它发挥作用的最安全的方法。当然,在做出任何更改后,您应该始终访问管理员中的永久链接页面。

http://wordpress.org/plugins/custom-post-type-ui/

如果你正确地创建了它,你可以创建一个自定义帖子类型的存档文件archive-games.php(这将是你的自定义帖子类型名称,例如,在你的功能文件中类似这样的东西

add_action('init', 'cptui_register_my_cpt_game');
function cptui_register_my_cpt_game() {
register_post_type('game', array(
'label' => 'Games',
'description' => '',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'post',
'map_meta_cap' => true,
'hierarchical' => false,
'rewrite' => array('slug' => 'game', 'with_front' => true),
'query_var' => true,
'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes','post-formats'),
'taxonomies' => array('category','post_tag'),
'labels' => array (
'name' => 'Games',
'singular_name' => '',
'menu_name' => 'Games',
'add_new' => 'Add Game',
'add_new_item' => 'Add New Game',
'edit' => 'Edit',
'edit_item' => 'Edit Game',
'new_item' => 'New Game',
'view' => 'View Game',
'view_item' => 'View Game',
'search_items' => 'Search Game',
'not_found' => 'No Game Found',
'not_found_in_trash' => 'No Game Found in Trash',
'parent' => 'Parent Game',
)
) ); }

当然,请确保您没有任何现有的带有子弹游戏的页面