Forum Discussion

skylinegtr's avatar
10 years ago

Custom components to show categories/title

Anyone have an example code to show the categories/Title and post count into custom component? I've tried but no luck. Example below. Thanks

 

 

 

image2.png

"type" : "board",
"id" : "pure_internal_forum",
"href" : "/boards/pure_internal_forum",
"view_href" : "/t5/Employee-Product-Discussion/bd-p/pure_internal_forum",
"conversation_style" : "forum",
"title" : "Employee Product Discussion",
"short_title" : "Employee Product Discussion",
"description" : "",
"parent_category" : {
"type" : "category",
"id" : "forums",
"href" : "/categories/forums",
"view_href" : "/t5/Forums/ct-p/forums"
},
"root_category" : {
"type" : "category",
"id" : "forums",
"href" : "/categories/forums",
"view_href" : "/t5/Forums/ct-p/forums"
},

 

  • OlivierS's avatar
    OlivierS
    10 years ago

    skylinegtr you can filter by id:

     

    SELECT id, title, boards FROM categories WHERE id IN('forums','kb')

     

  • OlivierS's avatar
    OlivierS
    Lithium Alumni (Retired)

    skylinegtr in future post, please list what you've been trying ;)

     

    Now, based on this tutorial, and the category resource, I assume this code would work:

     

    <h2>JOIN THE DISCUSSION</h2>
    <#--Use the rest FreeMarker context object, passing the rest_version parameter and LiQL query (encoded by appending ?url) -->
    <#assign categories = rest("2.0","/search?q=" + "SELECT id, title, topics.count(*), messages.count(*), views, view_href FROM categories ORDER BY topics.count(*) ASC"?url) />
    <ul>
    <#list categories.data.items as category > 
    <li><a href=“${category.view_href}”>${category.title}</a><br />
    
    Topics count: ${category.topics.count} <br />
    Messages count: ${category.messages.count} <br />
    
    </li>
    </#list>
    </ul>

     Disclaimer: I won't be responsible for any side effects of my code. Please test, test, and test on your stage environment first before pushing to production ...

    • skylinegtr's avatar
      skylinegtr
      Mentor

      The code below lists categories and the boards within them.

       

      <#assign category = rest("2.0","/search?q=" + "SELECT id, title, boards FROM categories"?url).data.items![] />
      <#list category as category>
      <h2>${category.title}</a></h2>
      <#assign board = rest("2.0","/search?q=" + category.boards.query?url).data.items![] />
      <ul>
      <#if board?size gt 0>
      <#list board as board>
      <li><a href="${board.view_href}">${board.title}</a></li>
      </#list>
      <#else>
      <li>No boards in this category</li>
      </#if>
      </#list>

       

      It shows the following:

       

                      Knowledge & Support

                     -Customer Knowledge Base

      • -Customer Product Ideas
        -Partner Knowledge Base
        -Internal Knowledge Base
        -TSE Notes
        Forums
        -Customer Product Discussion
        -Customer Tools, Tips & Tricks
        -Customer General Discussion
        -Partner Forum
        -Employee Product Discussion
        -Employee Social Discussion
        -TSE Discussion
        -SQL Experts Forum
        Idea Exchange
        Internal Idea Exchange
        @SupportOps
        Blogs
        -Ben's Support Sermon
        -Support News, Process, and Announcements
        -Bartz Blog

       

       If I only want the categories for the Forums or Knowledge and Support? How can I accomplish this?

      • OlivierS's avatar
        OlivierS
        Lithium Alumni (Retired)

        skylinegtr you can filter by id:

         

        SELECT id, title, boards FROM categories WHERE id IN('forums','kb')

         

    • skylinegtr's avatar
      skylinegtr
      Mentor

      OlivierS – Thanks for your help with this. Sorry, I should have been clearer.

       

      What I’m trying to do is to display 3 subject/topics for each category in the custom components.

       

      For example:

      The Blog has Topic/Subject- Bartz Blog, Ben’s Suport, Support News, Process

      Knowledge & Support has Topic/Subject-Customer Knowledge Base, Customer Product Ideas, Partner Knowledge Base.

      It’s my first time dealing with API’s. 

      Image13.png