简体   繁体   English

Wordpress漂亮的永久链接/ w漂亮的查询参数(用于排序),通过ModRewrite

[英]Wordpress pretty permalinks /w Pretty query parameters (For sort) via ModRewrite

I currently have wordpress pages that that can be viewed via both the index page (all the posts) and also the category pages. 我目前有wordpress页面,可以通过索引页面(所有帖子)和类别页面进行查看。

My current permalink structure is ' http://www.mysite.com/%postname%/ ' which is neat and i would like to keep. 我当前的永久链接结构是' http://www.mysite.com/%postname%/ ',它整洁,我想保留。

Current examples.. 当前示例

Home page (post list) http://www.mysite.com/ 主页(帖子列表) http://www.mysite.com/

Category page (filtered post list - filter on category) http://www.mysite.com/categoryname/ 类别页面(已过滤的帖子列表-按类别过滤) http://www.mysite.com/categoryname/

Any post list needs to be order (by choice of the user) by any of the following parameters... 任何帖子列表都需要通过以下任意参数排序(根据用户的选择)...

Oldest->Newest , Newest->Oldest , Expensive->Cheapest , Cheapest->Expensive , HighestRated->LowestRated , LowestRated->HighestRated 最旧->最新,最新->最旧,昂贵->最便宜,最便宜->昂贵,最高价->最低价,最低价->最高价

I have handled all the sorting correctly in the functions.php and it retrieves from from GET parameter set. 我已经在functions.php中正确处理了所有排序,并且它从GET参数集中检索。 (the last 4 are custom meta attributes which I have sorted/handled correctly) (最后4个是我正确排序/处理的自定义元属性)

Examples are... http://www.mysite.com?SortBy=Newest 例子是... http://www.mysite.com?SortBy=Newest

http://www.mysite.com/categoryname?SortBy=HighestRated http://www.mysite.com/categoryname?SortBy=HighestRated

I can't get a correct functioning .htaccess file with ModRewrite that achieves this.... 我无法通过ModRewrite获得正确的.htaccess文件,以实现此目标。

I would like them to look like these (for the 2 examples above) 我希望它们看起来像这样(对于上面的2个示例)

http://www.mysite.com/SortBy/Newest/ http://www.mysite.com/SortBy/Newest/

http://www.mysite.com/categoryname/SortBy/HighestRated http://www.mysite.com/categoryname/SortBy/HighestRated

My webserver is running Apache on Linux server. 我的网络服务器在Linux服务器上运行Apache。

My current .htaccess file looks like this... 我当前的.htaccess文件看起来像这样...

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

It doesn't seem to be doing my current re-write actions but I presume these are handled by Wordpress elsewhere?? 它似乎并没有执行我当前的重写操作,但我认为这些操作是由其他地方的W​​ordpress处理的?

Use the add_query_arg WordPress function. 使用add_query_arg WordPress函数。 WordPress is designed to reject any URL query parameters that it doesn't recognize. WordPress旨在拒绝任何无法识别的URL查询参数。 You will need to tell WordPress about the new parameter(s) you will be sending via a URL. 您将需要告诉WordPress您将通过URL发送的新参数。

Reference: http://codex.wordpress.org/Function_Reference/add_query_arg 参考: http : //codex.wordpress.org/Function_Reference/add_query_arg

"Retrieve a modified URL (with) query string. “检索修改的URL(带有)查询字符串。

You can rebuild the URL and append a new query variable to the URL query by using this function. 您可以使用此函数重建URL并将新的查询变量附加到URL查询。 You can also retrieve the full URL with query data." 您还可以检索包含查询数据的完整URL。”

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

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