我想在我的网站上实现以下链接结构:
属性aproperties
第页,共页properties
CPT,第1页
/properties/page/2->aproperties
第页,共页properties
CPT,第2页/属性/属性名称->单个properties
包含属性详细信息的页面
我有一个自定义帖子类型(CPT),名为property
. 注册如下:rewrite
规则指定为\'rewrite\' => array(\'slug\' => \'properties\', \'with_front\' => false)
:function property_post_type_init() {
$labels = array(
\'name\' => _x(\'Properties\', \'post type general name\'),
\'singular_name\' => _x(\'Property\', \'post type singular name\'),
\'add_new\' => _x(\'Add New\', \'property\')
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'rewrite\' => array(\'slug\' => \'properties\', \'with_front\' => false),
\'query_var\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'show_in_nav_menus\' => false,
\'menu_position\' => 5,
\'supports\' => array(
\'title\',
\'editor\',
\'revisions\'
)
);
register_post_type(\'property\',$args);
我还有一页写着slugproperties
permalink结构设置为/%category%/%postname%/
在Properties
第I页新建WP_Query
具有以下参数的对象:
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'post_type\' => \'property\',
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'paged\' => $paged
);
return $args;
我使用自定义分页代码(在functions.php中),该代码使用正确的URL正确生成分页:<my-site>/properties/
<my-site>/properties/page/2/
<my-site>/properties/page/3/
然而,当我点击分页中的任何页面时,我会被重定向到404页面。我需要查询参数,它们如下所示:[page] => 2
[property] => page
[post_type] => property
[name] => page
这是不对的!我不明白这些参数是从哪里来的:[page] => 2
[property] => page
[name] => page
我相信这和rewrite
注册CPT时的规则。如何实现以下设置以正确工作:
Aproperties
显示全部的页面properties
自定义贴子类型具有分页的贴子
Aproperties
自定义帖子类型\'rewrite\' => array(\'slug\' => \'properties\', \'with_front\' => false)
规则的永久链接/%category%/%postname%/
结构,因此我有以下链接结构:属性aproperties
第页,共页properties
CPT,第1页
/properties/page/2->aproperties
第页,共页properties
CPT,第2页/属性/属性名称->单个properties
包含属性详细信息的页面希望这是有意义的。谢谢,Dasha
最合适的回答,由SO网友:John P Bloch 整理而成
尝试将页面的slug更改为其他内容,并将您的帖子类型注册更改为:
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'has_archive\' => true,
\'show_ui\' => true,
\'rewrite\' => array(\'slug\' => \'properties\', \'with_front\' => false),
\'query_var\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'show_in_nav_menus\' => false,
\'menu_position\' => 5,
\'supports\' => array(
\'title\',
\'editor\',
\'revisions\'
)
);
有效的新论点是
\'has_archive\'
. 这是3.1中新增的,并为您提供
/properties/
,
/properties/page/2
, 默认为etc.结构。然后刷新您的重写规则,看看是否可以修复它。您可能还需要注释掉使用查询或重写规则编写的任何代码