WordPress自定义帖子模板将无法加载

时间:2013-03-15 23:07:46

标签: wordpress templates custom-post-type

我创建了一个自定义帖子,并创建了一个名为single-postname.php的模板文件

在我刚刚重新定向回主页之前,我无法加载模板文件,但在刷新.htaccess文件之后,我只得到一个空白页。

我尝试删除并再次添加帖子,更改了固定链接几次,并更改了主题,似乎没有任何效果。还有什么我可以尝试强制WordPress再次查找文件吗?

register_post_type

$labels = array( 
    'name' => _x( 'Conversations', 'conversation' ),
    'singular_name' => _x( 'Conversation', 'conversation' ),
    'add_new' => _x( 'Add New', 'conversation' ),
    'add_new_item' => _x( 'Add New Conversation', 'conversation' ),
    'edit_item' => _x( 'Edit Conversation', 'conversation' ),
    'new_item' => _x( 'New Conversation', 'conversation' ),
    'view_item' => _x( 'View Conversation', 'conversation' ),
    'search_items' => _x( 'Search Conversations', 'conversation' ),
    'not_found' => _x( 'No conversations found', 'conversation' ),
    'not_found_in_trash' => _x( 'No conversations found in Trash', 'conversation' ),
    'parent_item_colon' => _x( 'Parent Conversation:', 'conversation' ),
    'menu_name' => _x( 'Conversations', 'conversation' ),
);

$args = array( 
    'labels' => $labels,
    'hierarchical' => false,
    'description' => 'conversation between users on the site',
    'supports' => array( 'title', 'excerpt', 'author', 'comments', 'custom-fields' ),

    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'menu_position' => 20,
    //'menu_icon' => 'http://findicons.com/files/icons/2229/social_media_mini/24/google_talk.png',
    'show_in_nav_menus' => true,
    'publicly_queryable' => true,
    'exclude_from_search' => false,
    'has_archive' => true,
    'query_var' => true,
    'can_export' => true,
    'rewrite' => true,
    'capability_type' => 'post'
);

register_post_type( 'conversation', $args );

Filename = single-conversation.php

1 个答案:

答案 0 :(得分:1)

根据模板层次结构,如果您要在自定义帖子类型“xyz”下输出所有帖子的存档,那么您将创建一个名为“archive-xyz.php”的文件并将其放入您的页面模板中目录。如果您要在自定义帖子类型“xyz”下输出单个帖子,那么WordPress将查找名为“single-xyz.php”的文件。

http://codex.wordpress.org/Template_Hierarchy

我试图澄清:)