【问题标题】:Why aren't my custom post type posts showing up?为什么我的自定义帖子类型帖子不显示?
【发布时间】:2012-07-22 07:06:25
【问题描述】:

我创建了一个自定义帖子类型 - Press - 在functions.php中使用以下代码:

// Press Custom Post Type //

function press_custom_init() {

    $labels = array(
        'name' => _x('Press', 'post type general name'),
        'singular_name' => _x('Press', 'post type singular name'),
        'add_new' => _x('Add New', 'press'),
        'add_new_item' => __('Add New Press Item'),
        'edit_item' => __('Edit Item'),
        'new_item' => __('New Press Item'),
        'view_item' => __('View Press Item'),
        'search_items' => __('Search Press'),
        '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,
        'show_in_menu' => true,
        'show_in_nav_menus' => false,
        'query_var' => true,
        'rewrite' => array('slug','pages'),
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => 5,
        'supports' => array('title','editor','thumbnail','excerpt',)
      );

    register_post_type( 'press' , $args );
}
add_action( 'init', 'press_custom_init' );

我已经添加了该帖子类型的项目并在我的导航栏中添加了一个菜单项,但是当我单击链接时,我收到一条“未找到帖子”消息。

你可以在这里看到它:http://s13.mynewsitereview.com//press

请帮忙!

【问题讨论】:

  • 您是否刷新了永久链接设置?

标签: wordpress themes custom-post-type posts


【解决方案1】:

只需访问 WP-admin 中的永久链接页面http://yoursite.com/wp-admin/options-permalink.php 即可解决此问题。

为什么?

在 WordPress 中创建任何插件(帖子类型、分类法等)后,WordPress 需要更新/创建一组新的重写规则(假设您使用的是漂亮的永久链接)。您需要做的就是访问后端的永久链接页面,以便为您的新帖子类型等生成新规则。技术术语是刷新重写规则 (http://codex.wordpress.org/Function_Reference/flush_rewrite_rules)

【讨论】:

    猜你喜欢
    • 2022-07-20
    • 1970-01-01
    • 2017-03-12
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多