首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何添加额外的GET参数,以便用add_rewrite_rule发布到url?

如何添加额外的GET参数,以便用add_rewrite_rule发布到url?
EN

WordPress Development用户
提问于 2019-03-18 10:44:43
回答 1查看 326关注 0票数 1

我有一个博客,它有一个定制的post类型article,链接是http://example.com/article/lorem-ipsum

如何使用add_rewrite_rule向相同的post http://example.com/article/lorem-ipsum/readers添加新的链接样式,使部件readers向页面http://example.com/article/lorem-ipsum添加GET参数&showReaders=true

EN

回答 1

WordPress Development用户

回答已采纳

发布于 2019-03-18 11:07:42

您希望使用add_rewrite_endpoint,因为您所关心的是在URL的末尾。

代码语言:javascript
复制
function wpseo331941_reader_endpoint() {
    add_rewrite_endpoint('readers', EP_PERMALINK | EP_PAGES);
}
add_action('init', 'wpseo331941_reader_endpoint', 10, 0);
代码语言:javascript
复制
//When you want to check if the 'readers' is being used
if ( false !== get_query_var('readers', false) ){
    //....
}

请注意,false !==必须存在,因为您的查询变量"readers“将有一个空字符串作为其值。

票数 2
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/331941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档