I am working on a plugin that creates an inventory list page using an XML data file. For the sake of this example, let us say the inventory items are antique motorcycles or contemporary area rugs.
User activates my plugin and adds a short code to a page in order to display the inventory on a page called “Inventory.”
I want to introduce a details page so when the end user wants to enlarge the thumbnail picture or read more details about a specific motorcycle, he can click from site.com/Inventory to site.com/Inventory/somethingelse/ to find that information on another page.
What is the right way to code this? Some things I have considered are…
- Create another page and another short code and then hide the page from the menus
- Add rewrite rules to send these requests to a .php file in my plugin directory
What do you think?
Thanks for reading.
Create a custom post type
inventory
. You get a separate post editor, nice URLs for free. No need for a short code, because each post type has its own archive page. You may add custom meta data, taxonomies etc.Write an importer. Look at the WordPress importer, it uses XML too. This isnât very hard, just make sure the post type and all additional meta data are already registered.
What you’re trying to build is a fairly in-depth plugin, assuming it’s something you want to integrate with WordPress at all. I’m assuming here that the user isn’t ever updating the XML data from inside WordPress, but the fact that you want the user to be able to display data using shortcodes means that you’ll need some integration.
Because you’re looking to take control of URLs like
site.com/Inventory/somethingelse/
, you’ll need to look at adding your own rewrite rules usingadd_rewrite_rule()
. You’ll then need to add custom actions to control what happens when users access a specific re-written URL (parse_request
andtemplate_redirect
are where I’d look first). You’ll also need to package your own XML parser, as WordPress doesn’t come with one (beside SimplePie, although that’s specifically for RSS).One example you might want to look to for this is NextGEN Gallery. It does similar sorts of things in that it has custom URL handling for single images. It also uses XML and JSON for setting up image rotation queues, so you can take some leads from that as well.
I wish you luck with this. If you need more help, it would be best to break your problem down into smaller chunks and ask individual questions for each. Walking through the whole process of building a plugin like you describe is well outside the scope of a single question.