简体   繁体   中英

WordPress Plugin populating a Page with custom URL parameters

OK, I'm writing a WordPress plugin with a dedicated DB table. I want to display a given record using a WP page. I want to simply include a short code in the page that calls a function to get the url parameters and generate the content. 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. 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.

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). 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.

Without knowing all the details of your use-case, it is difficult to know if this is the best option or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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