add_rewrite_endpoint

函式
add_rewrite_endpoint ( $name, $places, $query_var = true )
引數
  • (string) $name Name of the endpoint.
    Required:
  • (int) $places Endpoint mask describing the places the endpoint should be added. Accepts a mask of: - `EP_ALL` - `EP_NONE` - `EP_ALL_ARCHIVES` - `EP_ATTACHMENT` - `EP_AUTHORS` - `EP_CATEGORIES` - `EP_COMMENTS` - `EP_DATE` - `EP_DAY` - `EP_MONTH` - `EP_PAGES` - `EP_PERMALINK` - `EP_ROOT` - `EP_SEARCH` - `EP_TAGS` - `EP_YEAR`
    Required:
  • (string|bool) $query_var Name of the corresponding query variable. Pass `false` to skip registering a query_var for this endpoint. Defaults to the value of `$name`.
    Required:
    Default: true
定義位置
相關方法
add_rewrite_tagadd_rewrite_ruleiis7_add_rewrite_ruleadd_site_metawp_write_post
引入
2.1.0
棄用
-

add_rewrite_endpoint: 這個函式是用來給WordPress重寫規則新增一個新的端點(自定義URL)。端點允許你在現有的URL末端新增額外的URL引數。你可以用這個函式在WordPress重寫規則中新增一個新的查詢變數和端點。

新增一個端點,如/trackback/。

新增一個端點會為所提供的位元掩碼指定的每個匹配位置建立額外的重寫規則。例如。

add_rewrite_endpoint( ‘json’, EP_PERMALINK | EP_PAGES ) 。

將為每個描述固定連結(post)或頁面的permastruct新增一個以”json(/(.*))?/?$”結尾的新重寫規則。這將被改寫為”json=$match”,其中$match是由端點重碼匹配的URL部分(例如,”[permalink]/json/foo/”中的”foo”)。

一個與端點同名的新查詢變數也將被建立。

當指定$places時,確保你使用EP_*常量(或使用位數OR操作符的組合),因為它們的值不能保證保持靜態(特別是`EP_ALL`)。

請確保在你的外掛被啟用和停用時重新整理重寫規則–見flush_rewrite_rules()。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function add_rewrite_endpoint( $name, $places, $query_var = true ) {
global $wp_rewrite;
$wp_rewrite->add_endpoint( $name, $places, $query_var );
}
function add_rewrite_endpoint( $name, $places, $query_var = true ) { global $wp_rewrite; $wp_rewrite->add_endpoint( $name, $places, $query_var ); }
function add_rewrite_endpoint( $name, $places, $query_var = true ) {
	global $wp_rewrite;
	$wp_rewrite->add_endpoint( $name, $places, $query_var );
}

常見問題

FAQs
檢視更多 >