PRO-Version: Create Pages

Usually the JCI-PLugin retrieves JSON from an API, converts the data with a template to HTML sand displays this HTML. That’s it.
From PRO-Version 3.4.0 on the JCI-Plugin also can create WordPress-Custom Posts (aka WordPress-pages) out of JSON.
This is how it works:

  • Step 1:
    Define / register a “Custom Post Type” in the Options of the JCI-plugin, there the Tab “Custom Post Types”.
    Here you have to define three parameters importains for the Custom PostType:
    – type: Singluar name of the Custom Post Type. The Plugin adds automatic “jci_” as prefix to avoid trouble with other plugins
    – ptredirect: Path for the URL of the created Custom Post
    – ptname: Menuname in the WordPress-Dashboard
    The keys and values have to be separated by “=” and the pairs by “;”. If you want to define more than one Custom Post Type separate by “##”. Example:
    type=mynewposttype;petredirect=herewego;ptname=MyCreatedPost##type=mynewposttype1;petredirect=herewego1;ptname=MyCreatedPost1
    Result:
    The WordPress-Admin-Menu should have the items “MyCreatedPosts” and “MyCreatedPost1”.
  • Step 2:
    Set Permalink “Post name”
    Click to the general Settings of WordPress, there “Permalinks” and select “Post name”-Radiobutton.
  • Step 3:
    Create JCI-template
    Click to the Plugins template-manager and insert some dummy text. Save it. Then browse the list of templates and get the id of this template, let’s call it TEMPLATE_ID_FOR_CUSTOM_POST.
    This template is used for building each single Custom Post (we enhance it later).
  • Step 4:
    Create a new WordPress Custom Page:
    There we place all we need to create Custom Posts like the shortcode (we do create one in the next step) and:
    Create a new “Custom Post Field”, named “jci_uniquekey_createpost” with a random, unique number (at least 10 characters, you’re free to create one). By this unique number all created Custom Posts can be found. Title of this page can be something like “Create Custom Post”.
  • Step 5:
    Set up a Shortcode in a new WordPress Page:
    Example:
    [jsoncontentimporterpro url=URL_WITH_DATA_FOR_ONE_OR_MORE_CUSTOM_POST parser=twig debugmode=10 id=TEMPLATE_ID_FOR_CUSTOM_POST]
    In detail:
    – url=URL_WITH_DATA_FOR_ONE_OR_MORE_CUSTOM_POST
    This is the URL with all the data need for one or more Custom Posts
    – id=TEMPLATE_ID_FOR_CUSTOM_POST: see Step 4
    – Additional Parameter: Up to now we’re creating a usual get-and-display-page. So if you need more parameter just add it. E.g. method=post, payload?=etc.
  • Step 6:
    View Creating Page
    Preview the so far Page with will later create the Custom Posts. You shoud see some debug-messages: Esp. the JSON-Code retrieved should be there. If not you have to check the Shortcode for missing parameter. Also the template-dummytext should be there (see Step 4).
    If this looks good publish this page.
  • Step 7:
    Check the JSON-data
    You should be familiar with the JSON you retrieve. You can copy paste the JSON into http://www.jsoneditoronline.org to see the structure. As you want to create a set of Custom Posts you need a set of data for that. You must identify the path to such a set in your JSON.
  • Step 8:
    Enhance Shortcode:
    Add mode and createoptions to your Shortcode (the one created in Step 5)
    Example:
    [jsoncontentimporterpro url=URL_WITH_DATA_FOR_ONE_OR_MORE_CUSTOM_POST parser=twig id=TEMPLATE_ID_FOR_CUSTOM_POST mode=create createoptions='{“type”:”mynewpagetype“, “loop”:”data”, “title”:”this is the title {{title}}: {{headline}}”, “slugname”: “{{title|replace({#SQM#/#SQM#: #SQM#-#SQM#})}}-{{headline | lower | replace({#SQM# #SQM#: #SQM#-#SQM#}) }}”, “deleteold”:”yes”}’]
    In detail:
    – mode=create: This sets an plugin-call into “create Custom Posts mode”
    – createoptions=…: JSON-coded parameter on how to build the Custom Posts.
    — “type”:”mynewpagetype“: This is the link to the Custom Post Type defined in Step 1
    — “loop”:”data”: The Plugin needs a set of data (aka array) in the JSON-data. This is defined here. See Step 7 for that.
    — “title”:”this is the title”: twig-template for building the Title of the created Custom Post. E.g. find in your JSON data for the Custom Post HTML-title. E.g. “{{title}}”.
    — “slugname”: “thisistheurl-add-some-individual-data”: twig-template for building the slug/URL of the created Custom Post. Finde something in the JSON-data for that, like “{{id}}”.
    — “deleteold”:”yes”: When creating new Custom Posts all previous Custom Posts are deleted (they are identified by “jci_uniquekey_createpost”, see Step 2)
  • Step 9:
    Create Custom Posts
    Publish the creating Custom Posts with the enhanced Shortcode and call it (you can switch off the template by adding “?show=oc”): This should create Custom Posts and show some debug-messages.
    The content of the created Custom Post should be the template-dummytext.
  • Step 10:
    Enhance the template
    Click to the Plugins template-manager and open the template with the dummytext. Here you can build the content which is put into the created Custom Posts. This depends on the JSON-data you have. If you need to call the API again for retrieving more, Custom Post-specific data you can do that by adding another [[jsoncontentimporterpro…]]-Shortcode parametrized by the data from the initial JSON-API-call.
  • Step 11:
    Create Pages
    Publish creating page and view it in the browser. You should see some debug-messages and the status of the creation-process.
  • Step 12:
    View
    In case of success in the WordPress-Menu a entry “ptname” (see Step 1) is created with a number of pages. Thes pages should be publshed pages with a URL “ptredirect”  (see Step 1) plus “slugname” (see Step 3)