自定义帖子类型存档页面未显示


11

我的网站上有一个名为“个人资料”的类别,我正在将该类别移至名为“个人资料”的自定义帖子类型。

我的问题是我无法显示此自定义帖子类型的存档页面。当我转到url时mywebsite.com/profiles,将我带到个人资料类别中某个帖子的单个帖子页面。

我已经包括has_archive = true;在我的functions.php

我在同一个网站上为另一个自定义帖子类型创建存档页面时没有问题,所以我真的迷失了为什么这次无法正常工作。

任何建议将不胜感激?

add_action( 'init', 'profile_custom_init' );

/* Here's how to create your customized labels */
function profile_custom_init() {
$labels = array(
    'name' => _x( 'Profiles', 'post type general name' ), // Tip: _x('') is used for localization
    'singular_name' => _x( 'Profile', 'post type singular name' ),
    'add_new' => _x( 'Add New', 'Profile' ),
    'add_new_item' => __( 'Add Profile' ),
    'edit_item' => __( 'Edit Profile' ),
    'new_item' => __( 'New Profile' ),
    'view_item' => __( 'View Profile' ),
    'search_items' => __( 'Search Profile' ),
    'not_found' =>  __( 'No Profile found' ),
    'not_found_in_trash' => __( 'No Profile found in Trash' ),
    'parent_item_colon' => ''
);

// Create an array for the $args
$args = array( 'labels' => $labels, /* NOTICE: the $labels variable is used here... */
    'public' => true,
    'publicly_queryable' => true,
    'has_archive' => true,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => 10,
    'supports' => array( 'title', 'editor','thumbnail', 'excerpt', 'custom-fields' ),
        'taxonomies' => array('category')
    ); 

    register_post_type( 'profile', $args ); /* Register it and move on */
}

尝试将个人档案类别标签更改为其他个人档案(例如,profiles-2)。
Vinod Dalvi

似乎不起作用。另外,例如,如果我转到mywebsite.com/his网址,而不是将我带到404页(我没有任何页面或帖子仅称为“ His”),它将带我到以“ his”一词开头的帖子。这看起来很奇怪吗?
13年

您是否尝试过再次保存永久链接结构?这将导致重新生成重写规则。
Mike Madern 2013年

通过单击“永久链接设置”的“保存更改”按钮,尝试重新保存永久链接结构。
Vinod Dalvi

Answers:


18
  1. 导航到设置->永久链接
  2. 将永久链接结构更改为默认
  3. 保存设置
  4. 更改为自定义结构或职位名称(或任何其他结构)
  5. 保存设置

这将重新写入htaccess文件,然后重新写入应该可以进行。


如果上述解决方案不起作用-应该与服务器配置有关。

Aapache2

跑: a2enmod rewrite && service apache2 reload

Nginx的

跟随:https : //do.co/2LjCF8r


希望这可以节省您的时间。


这为我解决了。
user2924019

3

重新保存永久链接结构似乎可以解决此问题。感谢小费迈克和维诺德。


1
我在Nikhil之前回答了这个问题,并认为这会有所帮助。自从他发布了更好的答案以来,我没有再检查。因此,指责我不对发布答案的人员表示赞赏,这有点不公平。
苦果

不好的是,我看了十月后的游行,以为是第二年。。您的稀疏答案加上这看起来像是在迅速获得信贷。看起来都可以),在问题和答案上都给了你赞成票
肯德(Kender)

@Kender-我无意获取别人回答或复制它的学分。我根据我的经验回答了问题,并详细解释了答案。它可能会帮助许多开发人员从CMS端以及服务器端解决此问题。
Nikhil
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.