在Word preSS使用自定义重写规则自定义、重写、规则、Word

由网友(無法言语の爱)分享简介:我想创建自定义的改写在Word preSS规则,使基于什么是查询字符串,我可以将数据传递到页面。I am trying to create custom rewrite rules in WordPress so that I can pass data to a page based on what is in t...

我想创建自定义的改写在Word preSS规则,使基于什么是查询字符串,我可以将数据传递到页面。

I am trying to create custom rewrite rules in WordPress so that I can pass data to a page based on what is in the query string.

我的页面正常工作: /零售商-AZ /?商家= some_merchant 然后还 ? /零售商-AZ /商人=一些 - 商家放大器;报价=一些-报价

My page works fine: /retailers-a-z/?merchant=some_merchant and then also /retailers-a-z/?merchant=some-merchant&offer=some-offer

我第一次尝试创建此在.htaccess重写规则,但由于认识字preSS有它自己的内部重定向数据库..所以经过了大量的研究,我设法想出下面code ......然而,它仍然没有工作..每当我尝试访问 /零售商-AZ /一些零售商 /零售商-AZ /一些零售商/部分要约它只是加载主页。

I first tried to create a rewrite rule for this in .htaccess but since realised WordPress has it's own internal redirection database.. so after a lot of research I managed to come up with the following code... However, it is still not working.. Whenever I try to access /retailers-a-z/some-retailer or /retailers-a-z/some-retailer/some-offer it just loads the home page.

的functions.php:

functions.php:

function wp_raz_rules()
{
  add_rewrite_rule(
    'retailers-a-z/([^/]+)/?$',
    'index.php?merchant=$matches[1]',
    'top'
  );

  add_rewrite_rule(
    'retailers-a-z/([^/]+)/([^/]+)/?$',
    'index.php?merchant=$matches[1]&offer=$matches[2]',
    'top'
  );

  add_rewrite_tag('%merchant%', '([^/]+)');
  add_rewrite_tag('%offer%', '([^/]+)');
}
add_action('init', 'wp_raz_rules');

function wp_raz_vars($vars)
{
  $vars[] = 'merchant';
  $vars[] = 'offer';
  return $vars;
}
add_filter('query_vars', 'wp_raz_vars');

然后我相信我可以用访问它们get_query_var('商人') get_query_var('报价')而不是 $ _ GET []

任何想法?感谢:)

推荐答案

管理通过明确定义的查询字符串的页面名称来修复它。

Managed to fix it by explicitly defining the page name in the query string.

的index.php页面名=零售商-A-Z&放大器;商家= $匹配[1]安培;报价= $匹配[2]

不是100%肯定,如果它是这样做的正确方法。

Not 100% sure if it is the correct way of doing it.

阅读全文

相关推荐

最新文章