【问题标题】:Custom post-type post wont show when using a custom template使用自定义模板时,自定义帖子类型的帖子不会显示
【发布时间】:2014-10-16 15:40:44
【问题描述】:

这是在我的注册帖子类型下的设置中:

register_post_type( 'support', /* (http://codex.wordpress.org/Function_Reference/register_post_type) */
    // let's now add all the options for this post type
    array( 'labels' => array(
        'name' => __( 'Support', 'bonestheme' ), /* This is the Title of the Group */
        'singular_name' => __( 'Support', 'bonestheme' ), /* This is the individual type */
        'all_items' => __( 'All support', 'bonestheme' ), /* the all items menu item */
        'add_new' => __( 'Add New', 'bonestheme' ), /* The add new menu item */
        'add_new_item' => __( 'Add New Support', 'bonestheme' ), /* Add New Display Title */
        'edit' => __( 'Edit', 'bonestheme' ), /* Edit Dialog */
        'edit_item' => __( 'Edit Support', 'bonestheme' ), /* Edit Display Title */
        'new_item' => __( 'New Support', 'bonestheme' ), /* New Display Title */
        'view_item' => __( 'View Support', 'bonestheme' ), /* View Display Title */
        'search_items' => __( 'Search Support', 'bonestheme' ), /* Search Custom Type Title */ 
        'not_found' =>  __( 'Nothing found in the Database.', 'bonestheme' ), /* This displays if there are no entries yet */ 
        'not_found_in_trash' => __( 'Nothing found in Trash', 'bonestheme' ), /* This displays if there is nothing in the trash */
        'parent_item_colon' => ''
        ), /* end of arrays */
        'description' => __( 'This is the example for a slide', 'bonestheme' ), /* Custom Type Description */
        'public' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'show_ui' => true,
        'query_var' => true,
        'menu_position' => 8, /* this is what order you want it to appear in on the left hand side menu */ 
        'menu_icon' => get_stylesheet_directory_uri() . '/library/images/custom-post-icon.png', /* the icon for the custom post type menu */
        'rewrite'   => array( 'slug' => 'support', 'with_front' => false ), /* you can specify its url slug */
        'has_archive' => 'custom_type', /* you can rename the slug here */
        'capability_type' => 'post',
        'hierarchical' => false,
        'taxonomies' => array('category'),
        /* the next one is important, it tells what's enabled in the post editor */
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'sticky')
    ) /* end of options */
); /* end of register post type */  

在此自定义帖子类型下创建页面时,它们会正确路由和永久链接。但是,当我加载页面时,会显示默认错误。

我还创建了 single-support.php 页面,目前它只是空白,因此我可以看到一个空白页面加载以确保其正常工作。

知道为什么这似乎不起作用吗?

【问题讨论】:

  • 这段代码在这里运行良好。你有什么问题?

标签: php wordpress


【解决方案1】:

来自 wordpress 帖子类型文档:

http://codex.wordpress.org/Post_Types

"注意:在某些情况下,必须更新永久链接结构才能使用新的 查看自定义帖子类型的帖子时要访问的模板文件。为此,请转到管理面板 > 设置 > 永久链接,将永久链接结构更改为不同的结构,保存更改,然后将其更改回所需的结构。 "

这正是解决问题的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-20
    • 1970-01-01
    • 2011-12-16
    • 2017-03-12
    • 1970-01-01
    • 1970-01-01
    • 2013-03-17
    • 1970-01-01
    相关资源
    最近更新 更多