【问题标题】:How to check if the currently viewed page is an endpoint in WordPress?如何检查当前查看的页面是否是 WordPress 中的端点?
【发布时间】:2014-03-28 20:28:07
【问题描述】:

我添加了一个端点来使用add_rewrite_endpoint()创作链接

我现在可以拥有如下链接:example.com/author/username/articles

要检查当前查看的页面何时是作者页面 (example.com/author/username),我可以这样做:

if ( is_author() )

但是如何检查当前查看的页面是否是我的新端点?即:example.com/author/username/articles

参考:

https://codex.wordpress.org/Rewrite_API/add_rewrite_endpoint https://codex.wordpress.org/Function_Reference/is_author

【问题讨论】:

    标签: php wordpress rewrite endpoints


    【解决方案1】:

    我找到了答案:

    global $wp_query;
    isset( $wp_query->query_vars['articles'] )
    

    【讨论】:

    • 在某个时候你必须写一篇博文:Mastering endpoints, by henry wright ;)
    • @brasofilo 有人打败了我 :) - 看看这篇文章,它解释了一切:make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api
    • 或使用get_query_var( 'articles', false ) !== false
    • 如果某些将set_query_var('articles', $articles) 传递到模板范围内,这将不起作用。
    猜你喜欢
    • 1970-01-01
    • 2013-12-08
    • 1970-01-01
    • 2015-05-10
    • 2011-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-29
    相关资源
    最近更新 更多