简体   繁体   English

子页面的WordPress自定义永久链接

[英]Wordpress custom permalink for subpages

Simply put, I have a page called 'products' (not a post, but a page, not to confuse). 简而言之,我有一个名为“产品”的页面(不是帖子,而是一个页面,不要混淆)。 Which is perfectly accessable through: 可以通过以下方式完美访问:

domein.com/products/ domein.com/products/

On this page it shows the template matched with the page 'products'. 在此页面上,显示了与页面“产品”匹配的模板。 So far so good, this is basic wordpress. 到目前为止,一切都很好,这是基本的wordpress。

Now, on that page I have post categories listed. 现在,在该页面上,我列出了帖子类别。 I want to put the categories listed on that page in my permalink like this: 我想将页面上列出的类别放在我的永久链接中,如下所示:

domein.com/products/category_slug domein.com/products/category_slug

This currently gives a 404, fair enough, it is not a page. 目前,这给出了404,这很合理,它不是页面。 However, I want wordpress to show the template of the 'products' page and it need to pass along the category_slug as a variable so I can process it in the template of products. 但是,我希望wordpress显示“产品”页面的模板,它需要将category_slug传递为变量,以便可以在产品模板中对其进行处理。

Problem is that I have tried to adjust the htaccess file but I don't seem to be able to figure out where in wordpress I need to make these changes. 问题是我试图调整htaccess文件,但我似乎无法弄清楚我需要在wordpress中进行哪些更改。 I tried: 我试过了:

RewriteEngine On
RewriteBase /
RewriteRule ^products/(.*) /index.php/products?cat=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php/$1

But this doesn't work. 但这是行不通的。 Anybody any suggestions or any direction where to start looking? 任何人有任何建议或任何方向从哪里开始寻找? Do I need to change this in the htaccess file or is there a php engine file that processes these things? 我需要在htaccess文件中更改此设置,还是有处理这些内容的php引擎文件? Thanks in advance 提前致谢

For those looking for the anwser, found out that there is a hook in wordpress for it: 对于那些寻找答案的人,发现在wordpress中有一个钩子:

add_filter('rewrite_rules_array','function_name');

function function_name($rules) {
    $new_rules['url_to_rewrite'] = 'index.php?pagename=pagename';

    return $new_rules + $rules;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM