WordPress函数:add_permastruct 添加永久链接结构

江河/ 01月27日/ WordPress/ 浏览 323

函数原型:


add_permastruct( string $name, string $struct, array $args = array() )


添加永久链接结构


参数说明:


$name 链接名称


$struct 链接结构


$args 有关从permalink结构构建规则的参数,请参阅WP_Rewrite::add_permstruct()以获取完整详细信息。


函数源码:


function add_permastruct( $name, $struct, $args = array() ) {
	global $wp_rewrite;

	// Back-compat for the old parameters: $with_front and $ep_mask.
	if ( ! is_array( $args ) ) {
		$args = array( 'with_front' => $args );
	}

	if ( func_num_args() === 4 ) {
		$args['ep_mask'] = func_get_arg( 3 );
	}

	$wp_rewrite->add_permastruct( $name, $struct, $args );
}


使用举例:


global $wp_rewrite;
$args = array(
    'with_front' => true,
    'ep_mask' => 3,
    'paged' => 1,
    'feed' => 1,
    'forcomments' => 0,
    'walk_dirs' => 1,
    'endpoints' => 1
);
add_permastruct( 'locations', 'test/%message/', $args);


发表评论

暂无评论,抢个沙发...

客服 工单