• I am creating a plugin that connects to a remote API that has car listings and displays the data that’s returned in that call.

    The plugin essentially does not need to interact with the WordPress database at all.

    I already know I can use things like wp_remote_get, file_get_contents and file_get_contents to retrieve that data.

    My problem is that I’m not sure if I should be creating a plugin for this or just shortcodes or page-templates or what.

    I want the urls to look like

    `example.com/cars/ //Cars listing results
    example.com/cars/2 //Page 2 of Cars listing results
    example.com/cars/?doors=4&engine=v8 //Search parameters for Cars listing results
    example.com/car/1234 //Car info page 1234 is the car_id`

    I was thinking I could create pages in WordPress called cars and car and then create custom shortcodes that would hook into some functions I build to interact with the API, but for some reason that doesn’t seem like the best idea to me.

    Can anyone recommend a better structure for setting this up?

Viewing 3 replies - 1 through 3 (of 3 total)
  • I was thinking I could create pages in WordPress called cars and car and then create custom shortcodes that would hook into some functions I build to interact with the API, but for some reason that doesn’t seem like the best idea to me.

    Yes to this scheme.
    Put the shortcode handler etc into a plugin.
    There will be some interaction with your theme, it is likely to need some customising. Do this by setting up a child theme if you are not using one already, here is how:
    creating a child theme http://codex.wordpress.org/Child_Themes

    Thread Starter bigmike7801

    (@bigmike7801)

    Would I put all of the markup within the shortcode handlers? Can I create template files that my shortcodes use?

    I guess I’m having a hard time understanding where all the markup goes.

    Thanks for your response.

    Yes, most if not all your markup would be returned by your shortcode handler (please realise that the shortcode handler RETURNS the desired text, it does not ECHO or otherwise output text).

    You could put all of your code in a custom page template, your shortcode would be register there too. Then you would not need a plugin.

    There are always many ways of partitioning a solution. Skills and experience, future plans and so on inform this choice. For instance a plugin can have a configuration/control panel.
    Also page templates are tied to your theme, is this important ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to structure WordPress plugin to display data from API’ is closed to new replies.