简体   繁体   English

WordPress插件使用自定义URL参数填充页面

[英]WordPress Plugin populating a Page with custom URL parameters

OK, I'm writing a WordPress plugin with a dedicated DB table. 好的,我正在编写带有专用数据库表的WordPress插件。 I want to display a given record using a WP page. 我想使用WP页面显示给定的记录。 I want to simply include a short code in the page that calls a function to get the url parameters and generate the content. 我想在页面中简单地包含一个短代码,该代码调用一个函数来获取url参数并生成内容。 Simple so far. 到目前为止很简单。 The problem I'm having is I can't find a way use mo_rewrite with WP to have URLS like this: http://site.com/page/mydbrecordid I also want http://site.com/page/ to activate the same function obviously with some default output. 我遇到的问题是我找不到与WP一起使用mo_rewrite的方式来拥有这样的URL: http ://site.com/page/mydbrecordid我也想激活http://site.com/page/相同的功能显然带有一些默认输出。 I can't find a similar use case documented anywhere. 我在任何地方都找不到类似的用例。

Thanks! 谢谢!

Perhaps instead of using mod_rewrite to transform your friendly URLs into parameterized ones, you could simply hook the 'template_redirect' action, then render whatever you want according to the path in $_SERVER['REQUEST_URI'] and any other URL parameters. 也许无需使用mod_rewrite将友好的URL转换为参数化的URL,您只需钩住'template_redirect'操作,然后根据$ _SERVER ['REQUEST_URI']中的路径和任何其他URL参数呈现所需的内容。

One thing you could do in the action function is to pull page content from the DB, evaluate it using do_shortcode() and apply the usual filters (wpautop, convertchars, wptexturize). 您可以在动作函数中做的一件事是从数据库中提取页面内容,使用do_shortcode()对其进行评估,然后应用常用的过滤器(wpautop,convertchars,wptexturize)。 That way, you can register your own shortcodes to pull data from your custom table and use them in any page/post/widget, including pages you render from the template_redirect action hook. 这样,您可以注册自己的简码以从自定义表中提取数据,并将其用于任何页面/帖子/小部件中,包括从template_redirect操作挂钩呈现的页面。

Without knowing all the details of your use-case, it is difficult to know if this is the best option or not. 在不了解用例的所有细节的情况下,很难知道这是否是最佳选择。

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

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