Php 使后续URL保留查询变量。

Php 使后续URL保留查询变量。,php,wordpress,Php,Wordpress,我有下面的代码,允许我在我的WP网站上使用基于给定url的自定义模板 //* Create Variables for URL Templates function sjc_add_query_vars($vars) { return array('template') + $vars; } add_action('query_vars', 'sjc_add_query_vars',10,1); //* Load Cutstom Page Templates by URL function s

我有下面的代码,允许我在我的WP网站上使用基于给定url的自定义模板

//* Create Variables for URL Templates
function sjc_add_query_vars($vars) {
return array('template') + $vars;
}
add_action('query_vars', 'sjc_add_query_vars',10,1);

//* Load Cutstom Page Templates by URL
function sjc_template($template) {
global $wp;
if ($wp->query_vars['template']=='basic') {
global $post;
$posttype = get_post_type($post->ID);
return dirname( __FILE__ ) . '/single-'. $posttype .'-basic.php';
}
else {
return $template;
}
}
add_filter( 'template_include', 'sjc_template', 99 );

这很有效。问题是,如果单击该页面上的任何链接,url将恢复,并使用默认模板。那么,有没有办法让自定义模板页面上的任何链接继续使用该自定义模板

您有很多选择。创建一个保留变量的搜索结果模板也许是最明智的方法,但是你可以做一些事情,比如写一个cookie,将它们存储在会话中或者


一般来说,WP希望您使用搜索结果模板文件。该文件将保留查询变量。

我查看了所有我能找到的关于使用搜索结果模板的文档,但没有一个有用。查询变量已在加载自定义模板。但如果用户单击该页面上的链接,我需要它留在该模板中。因此,例如,如果用户转到www.example.com/?template=basic并单击指向www.example.com/next/的链接,则应将他们转到www.example.com/next/?template=basicI,他们更愿意使用PHP来完成此操作,但现在我可以使用以下脚本使用JS来完成此操作:jQuerydocument.readyfunction{jQuerya.attrref,functioni,href{return href+'?template=basic';};};