2013-12-10 76 views
-1

我已经在WordPress 3.7.1中设置了“游戏”的自定义文章类型。一切正常,我创建了这个帖子类型的几个项目,并为它们创建/分配了类别。显示来自此CPT的帖子的查询按其应有的方式运行,并且我的自定义单页(single-game.php)也可以运行。WordPress的自定义文章类型存档未加载

但是,当我创建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); 
} 

此功能是一个自定义插件,我为此目的而订立的一部分,被称为的“初始化”钩构造。

任何帮助表示赞赏。

谢谢!

+0

当你说“分页不工作”,解释其不工作。 – Sinkingpoint

+0

分页档案页面上是回国一个404错误。 – RyanPhil

回答

0

我使用这个插件来创建我的自定义文章类型,一旦它启动并且有一个选项可以导出php代码,然后将其添加到函数文件中,然后禁用该插件。对我来说,这是确保我工作的最安全的方式。当然,在做任何改变之后,你总是应该访问管理员的永久链接页面。

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

如果你创建正确,您可以创建自定义类型后归档文件归档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', 
) 
)); } 

当然,确保你没有与蛞蝓游戏的任何现有网页

相关问题