BC Blog Export Helper

Originally posted by @Adam.Wilson:
For Treehouse meeting #4, here is the “BC Blog to Treepl Migration” code snippet if interested.

Any questions and/or feedback most welcome.

{% comment -%}
NOTES:
- Adjust ASSIGNs (Liquid variables) below with your values.
- Light grey columns are hard coded values for Treepl import
- If using Authors, set up the Authors in Treepl first and note their system IDs;
Then find and replace Author names with corresponding Treepl Author IDs when in your spreadsheet. (as we need to import with ID values only)
- If over 500 posts? batch collection with skip/limit as needed.
{% endcomment -%}

        {% assign BCblogID = 4989 %}
        {% assign TreeplTemplateID = 1815 %}

{module_data resource="blogs" version="v3" fields="id,siteId,blogId,postTitle,postFeaturedImage,postBody,createBy,releaseDate,blog,author,enabled" subresource="posts" resourceId="{{BCblogID}}" skip="0" limit="500" order="-releaseDate" collection="posts"}

            <table border="1">
                <thead>
                    <tr>
                        <th>External ID</th>
                        <th>Item Name</th>
                        <th>Item Description</th>
                        <th>Release Date</th>
                        <th style="background:lightgray;">Expiry Date</th>
                        <th style="background:lightgray;">Weight</th>
                        <th style="background:lightgray;">Template ID</th>
                        <th>Enabled</th>
                        <th>Classifications</th>
                        <th>Item Tags</th>
                        <th style="background:lightgray;">Created By Member Id</th>
                        <th style="background:pink;">Author</th>
                        <th>Image</th>
                    </tr>
                </thead>
                <tbody>
                {% for p in posts.items %}
                    <tr>
                        <td>{{p.id}}</td>
                        <td>{{p.postTitle}}</td>
                        <td>{{p.postBody | escape}}</td>
                        <td>{{p.releaseDate | date: "%M\/%d\/yyyy"}}</td>
                        <td style="background:lightgray;">1/1/2099</td>
                        <td style="background:lightgray;">0</td>
                        <td style="background:lightgray;">{{TreeplTemplateID}}</td>
                        <td>{{p.enabled}}</td>
                        <td>
                        {module_data resource="blogposts" version="v3" fields="category" subresource="categories" resourceId="{{p.id}}" skip="0" limit="100" order="objectType" collection="postCats"}
                        {% if postCats.totalItemsCount > 0 -%}
                        {% for i in postCats.items -%}{{i.category.category}}{% if forloop.last -%}{% else -%},{% endif -%}{% endfor -%}
                        {% endif -%}
                        </td>
                        <td>
                        {module_data resource="blogposts" version="v3" fields="tag" subresource="tags" resourceId="{{p.id}}" skip="0" limit="100" order="objectType" collection="postTags"}
                        {% if postTags.totalItemsCount > 0 -%}
                        {% for i in postTags.items -%}{{i.tag.tagName}}{% if forloop.last -%}{% else -%},{% endif -%}{% endfor -%}
                        {% endif -%}
                        </td>
                        <td style="background:lightgray;">0</td>
                        <td style="background:pink;">{{p.author.firstName}} {{p.author.lastName}}</td>
                        <td>{{p.postFeaturedImage}}</td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
1 Like

Do you have a link to the Treehouse #4 video? I looked on Facebook and don’t see a link. Thanks!

Hi @Darren_Kincaid.
Treehouse Meeting #4 - https://youtu.be/RzJI3cH_qYo

Thanks Alex (thanks Adam!) - going to be very handy

@Alex_B_Centrifuge I got this working no problem on a few sites but now suddenly I have a site it wont work on. I have double checked the blog code and ensured that liquid was enabled but strangely I can see the module data code at the top of the page which is normally hidden if it lists all the content - http://toprydeearlylearning.com.au/blog-listing could it there be any other reason it wouldn’t work on a site?

Check you quotation marks. Ensure they are regular ones and not ‘smart quotes’.

Hi @SiroccoDigital. In further testing I get the same result on a site that’s on the Silver plan. And looking back on those new BC plans, module_data wasn’t included in Silver! Only Gold and Platinum.
The old WebMarketing plan allowed module_data though :frowning:
You may have to temporarily upgrade if that’s the case with your site :grimacing:

Although I think you can get most of this data out with the regular Blog module tag, just not the categories/tags.

You totally nailed it @Adam.Wilson! I only just upgraded this site too so that I could take out one more month of hosting too :roll_eyes: As suggested, I upgraded to Gold and it worked straight away.

Direct link to time in Video when they start talking about this: https://youtu.be/RzJI3cH_qYo?t=1568
Might help someone later coming back to this.

2 Likes