API: curated.co

Task: Get data from curated.co via it’s API
Solution:
curated.co gives you a list of “issues”. You can generate for each issue a WordPress-pages (aka “Custom Post Type”) -for that you need:
  1. One WordPress-Pages called “generating-page”: This page is in the center and every time it is called new pages are created.
  2. One Plugin-template called “pattern-template”: There all information on how to connect the API is stored and what data is displayed on the generated pages.
  3. At least we have to tell your WordPress-Installation, that there is a new “Custom Page Type”.
In Detail:
  1. “generating-page”: Put this on a new WordPress-page: [jsoncontentimporterpro id=TEMPLATE_ID_PATTERN_TEMPLATE mode=create createoptions='{“type”:”curatedtype”, “loop”:”issues”, “title”:”Issue-number: {{number}}”, “slugname”: “slugname{{number}}”, “deleteold”:”yes”}’] (“loop” is the path to the list of issues in the JSON: Other JSON, other value here!) Add a “Custom Post Field” named “jci_uniquekey_createpost” with a random numer on that page (at least 10 chars). Preview that page: It says that the template with id=TEMPLATE_ID_PATTERN_TEMPLATE  does not exist.
  2. Add a new plugin-template with these settings. The number of this template is TEMPLATE_ID_PATTERN_TEMPLATE :
    • twig-code: summary: {{summary}} number: {{number}} title: {{title}} url: {{url}} published_at{{published_at | date("d.m.y, H:i")}}
    • unique-templatename: e.g. “curatedco-pagegenerator”
    • URL: https://api.curated.co/PUBLICATION_KEY/api/v1/issues
    • Method: CURL_GET
    • Curloptions: CURLOPT_HTTPHEADER=Accept:application/json##Authorization:Token token=YOUR_API_TOKEN##Content-type:application/json
  3. Edit “generating-page”: Set TEMPLATE_ID_PATTERN_TEMPLATE  with the numer of the generated plugin-template.
  4. Preview the “generating-page” again: You should get a message displayed “Pagetype not defined in plugin-options”. Click on the offered link will take you to the plugins options: Insert type=curatedtype;ptredirect=curatedredirect;ptname=curatedname there and save it. Click on “Custom Post Type”-Tab: You should see a new menuentry “curatedname” in the Admin-Menu: This is the place where the new pages will be (rename it via “ptname” as you like).
  5. Preview the “generating-page” again:There should be “start looping” where the issues are used for generating pages. The generated pages do have URLs like “…/curatedredirect/slug179/”: “curatedredirect” is the value of “ptredirect” (change as you like), “slug{{number}}” comes from the “createoptions”-JSON in the Shortcode of the generating-page. Same is with the title of the page: “Issue-number: {{number}}”
  6. If the URL gives a “page not found”-error: The “Permalink Settings” of the WordPress must be at “Post name”. Check that at the general WordPress “Settings” > “Permalinks”