是否有可能找出當前的WordPress網址是否爲端點頁面?檢查地址網址以檢查它是否有端點
- 漂亮的永久鏈接都在使用
- 可以遲到問,wp_head後,但前面是更好
只有使用:
global $wp_query;
isset($wp_query->query_vars['articles'])
是不工作正確。我不能接受這個答案。請沒有鏈接。
它似乎更像這個問題。上面的例子returns true
在slu is爲'articles'
的檔案頁上,或者當使用此slu or的單獨頁面或使用'articles'
的另一個獨特頁面的自定義帖子類型不是重寫規則端點「指向目標」時。
注意:它也returns true
如果有人有set_query_var('articles', $articles)
將它傳遞到模板範圍。 (否則,提供的功能低於確實工作,直到我偶然發現了模板文件插件)。
該問題在其他示例中仍然存在,如果在set_query_var()
中設置了變量,則爲「位置」或「地址」。
遍歷數據庫中的所有post_name
僅返回帖子和頁面slu to以從檢查部分「刪除」。自定義歸檔的重寫規則不在數據庫中。
從AMP頁面開始,端點可能位於url的開頭或末端,因此定位條件檢查也不起作用。
唯一的幫助到目前爲止,這是函數發現某處(板缺):
function is_endpoint(){
if(!get_option('permalink_structure')) return false;
global $wp;
if(!$wp->request) return false;
$parts = explode('/', $wp->request);
if(empty($parts)) return false;
// https://codex.wordpress.org/Reserved_Terms
$reserved = array(
'revision',
'nav_menu_item',
'custom_css',
'customize_changeset',
'action',
'attachment',
'attachment_id',
.. AND ALL OTHER FROM CODEX DOCS ...
'year'
);
//global $wp_query (clashes with added stuff);
global $wp_the_query;
foreach($parts as $maybe_endpoint){
if(!$maybe_endpoint || !trim($maybe_endpoint)) continue;
$maybe_endpoint = trim($maybe_endpoint);
if(post_type_exists($maybe_endpoint)) continue;
if(in_array($maybe_endpoint, $reserved)) continue;
/** if(is_slug($maybe_endpoint)) continue;**/ // MAYBE SOMETHING LIKE THIS?
/* Final conditional, all other possibilities removed: */
if(isset($wp_the_query->query_vars[$maybe_endpoint])) {
return true;
break;
}
}
return false;
}
但似乎它有檢查重寫規則以及排除存檔/註冊分類蛞蝓。
對此有任何可能的輸入?
這真的很有趣可以解決 –