I m trying to write a wordpress plugin that searches allows for the "third segment" of the URI to be a parameter.
因此,例如,我的基本联系结构如下:%/%post%
。
I ve got a category for "myplugin" and a post called "myitem"
this would be accessible via: /myplugin/myitem
I need to be able to add a third parameter: /myplugin/myitem/the_item_identifier
在我旁边,我有某种逻辑可以处理这个案件,像这样的情况。
function myplugin_hook_before_uri_read(){
$fields = explode( / ,$_SERVER["REQUEST_URI"]);
if (count($fields) == 4 && $fields[1] == "myplugin" && $fields[2] == "myitem") {
// fix things so we re redirected into the correct post.
}
}
to be fair, I could probably manage the same effect by using the URI /myplugin/myitem/?the_item_identifier
So maybe it s not the end of the world. Though I d feel a lot cleaner if I could work without the ?
另外,如果能以更好的方式添加一 h,请就此发言。 我不与这种方法结婚,这只是我能够想实现的唯一途径。
EDIT in response to Chris question below,
in this case, the_item_identifier
is the primary key from a third party XML document.
例如,如果是产品清单,我就有一个单一职位,即产品“显示模板”。