archive- {post_type} .php在slug更改时中断

时间:2015-05-09 12:57:27

标签: php wordpress custom-post-type slug

所以我有一个名为'events'的自定义帖子类型,只要slug与自定义帖子类型名称相同,它就可以正常工作。即http://website.com/events。 Wordpress很好地利用了archive-events.php

但问题是我将页面层次结构更改为http://website.com/news/events。现在Wordpress不再使用archive-events.php

问题可能在于重写规则吗?我尝试过几次改动但似乎没有解决这个问题。这是代码:

//* Add Events post type...
$event_labels = array( 
    'name'                  => _x( 'Events', 'Post Type General Name', 'events' ),
    'singular_name'         => _x( 'Event', 'Post Type Singular Name', 'events' ),
    'all_items'             => __( 'All Events', 'events' ),
    'add_new'               => __( 'Add New', 'events' ),
    'add_new_item'          => __( 'Add New Event', 'events' ),
    'edit_item'             => __( 'Edit Event', 'events' ),
    'new_item'              => __( 'New Event', 'events' ),
    'view_item'             => __( 'View Event', 'events' ),
    'search_items'          => __( 'Search Events', 'events' ),
    'not_found'             => __( 'No Event found', 'events' ),
    'not_found_in_trash'    => __( 'No Events found in Trash', 'events' ),
    'parent_item_colon'     => __( 'Parent Event:', 'events' ),
    'menu_name'             => __( 'Events', 'events' ),
);

$event_args = array( 
    'labels'                => $event_labels,
    'hierarchical'          => false,
    'description'           => 'Events.',
    'supports'              => array( 'title', 'editor', 'thumbnail' ),
    'public'                => true,
    'show_ui'               => true,
    'show_in_menu'          => true,
    'menu_icon'             => 'dashicons-calendar',
    'menu_position'         => 5,
    'show_in_nav_menus'     => true,
    'publicly_queryable'    => true,
    'exclude_from_search'   => false,
    'has_archive'           => true,
    'query_var'             => 'events',
    'can_export'            => true,
    'rewrite'               => array( 
        'slug'              => 'news/events', 
        'with_front'        => true,
        'feeds'             => true,
        'pages'             => true
    ),
    'capability_type' => 'post'
);

register_post_type( 'events', $event_args );

任何建议都将不胜感激!!

1 个答案:

答案 0 :(得分:0)

大新。在我更换了slug之后,我需要刷新永久链接以使其发生。问题现在解决了谢谢!