查询字符串参数在重写规则中丢失
-
-
您如何在页面模板中检索参数?也许问题就在那里.How are you retrieving the parameter in you page template? Perhaps the issue is there.
- 0
- 2011-08-22
- montrealist
-
您确定重写了吗?在single-book.php中有什么?您如何在该文件中获取letter变量?Are you sure it's something with the rewrite? And something in single-book.php? How are you getting the letter variable in that file?
- 0
- 2011-08-22
- chrisguitarguy
-
@dalbaeb啊,这应该已经在原始帖子中了.我已经编辑了.@dalbaeb Ah, this should have been in the original post. I've edited it in.
- 0
- 2011-08-22
- Rebecca Chernoff
-
@ChristopherDavis啊,这应该已经在原始帖子中了.我已经编辑了.@ChristopherDavis Ah, this should have been in the original post. I've edited it in.
- 0
- 2011-08-22
- Rebecca Chernoff
-
1 个回答
- 投票数
-
- 2011-08-22
我认为问题可能出在您的前端代码上.
尝试一下:
<?php if( $letter = get_query_var( 'letter' ) ) { echo 'Current Letter: ' . $letter; } else { echo 'Current Letter: All'; }
I think it's probably your front end code that's the problem.
Try this:
<?php if( $letter = get_query_var( 'letter' ) ) { echo 'Current Letter: ' . $letter; } else { echo 'Current Letter: All'; }
-
不.):网址仍然以`/books/the-dictionary`结尾,并且所有(现在有3种)提取qs var的方式都是空的.Nope. ): The url still ends up as `/books/the-dictionary` and all (now 3) ways of pulling the qs var are empty.
- 0
- 2011-08-22
- Rebecca Chernoff
-
这有点远,但是用下面的命令替换您在functions.php中的前两个函数(my_init和add_books_rewrite):http://pastie.org/2411828并删除add_filter('init')...)行.然后尝试通过转到"永久链接设置"页面并点击保存来手动刷新重写规则.This is sort of a long shot, but replace your first two functions in `functions.php` (`my_init` & `add_books_rewrite`) with this: http://pastie.org/2411828 and delete your add_filter('init' ...) line. Then try manually flushing your rewrite rules by going to your permalinks settings page and hitting save.
- 0
- 2011-08-22
- chrisguitarguy
-
而且您可能还想尝试在`add_rewrite_rule`正则表达式末尾删除美元符号.And you may want to try deleting the dollar sign at the end of your `add_rewrite_rule` regex as well.
- 0
- 2011-08-22
- chrisguitarguy
-
因此,您认为表示一切正常的Rewrite Analyzer是一个红色鲱鱼吗?嗯,会尝试的.So you think the Rewrite Analyzer indicating things are ok is a red herring? Hmm, will try.
- 0
- 2011-08-22
- Rebecca Chernoff
-
是的...没有变化.Yeah...no change.
- 0
- 2011-08-22
- Rebecca Chernoff
-
我只是发现WP重定向URL很奇怪-可能与规范重写有关.如何使用add_rewrite_endpoint:http://codex.wordpress.org/Rewrite_API/add_rewrite_endpoint'add_rewrite_endpoint('letter',EP_PERMALINK);`.用它代替add_rewrite_rule看看会发生什么I just find it weird that WP is redirecting the URL -- probably something to do with the canonical rewriting. What about using add_rewrite_endpoint: http://codex.wordpress.org/Rewrite_API/add_rewrite_endpoint 'add_rewrite_endpoint( 'letter', EP_PERMALINK );`. Use that instead of add_rewrite_rule and see what happens
- 0
- 2011-08-22
- chrisguitarguy
我已经成功添加了自定义帖子类型,并且永久链接结构很好用.因此,例如,我有一个自定义帖子类型
books
,而该书的永久链接为/books/the-dictionary
.我的
single-book.php
页面模板接受一个letter
参数来自定义页面上显示的内容.我希望能够像/book/the-dictionary/q
那样链接到此.我已经在主题的functions.php文件中添加了以下内容:
使用上面的刷新代码进行了几次尝试,手动进入永久链接设置页面并保存,并修复了正则表达式中的愚蠢错误,但最终我能够通过使用 Jan Fabry的很棒的重写分析器插件.
因此,从这里开始,我认为航行顺利,对吗?是的...不完全是.
当我加载我的网站并转到
books/the-dictionary/q
时,它确实正确加载了the-dictionary
内容,但是丢失了参数.我发现有趣的是,如果加载index.php?pagename=the-dictionary&letter=q
,一切都会很好.要检索参数,我有以下代码:
我也一直在看
$_SERVER["QUERY_STRING"]
.当我使用index.php?pagename...&letter...
时填充这些,但是当我使用/books/pagename/letter
时不会填充.因此,似乎这里发生了一些事情. WordPress不会完全删除该参数,因为如果我使用适当的querystring变量指定index.php,事情就可以进行了.这似乎表明重写规则无法正常工作.但是,Rewrite Analyzer插件似乎说我已经准备好正确的设置.
对于解决断开连接的问题,我有些困惑.抱歉,如果我缺少明显的内容. ):