Show all articles on Section page

5 Commentaires

  • Ifra Saqlain
    Community Moderator

    Hey Kyle,

    You should try this code for showing all articles on section page.

    Copy this script code and paste on your script.js template at the bottom:

    $(document).ready(function(){
    $.getJSON(' /api/v2/help_center/articles', function (data) {
    console.log(data);
    var articleList = '';
    $.each(data.articles, function (idx, itm) {
    articleList += '<li>';
    articleList += '<a href="' + itm.html_url + '" id="' + itm.id + '">'
    + itm.title + '</a>';
    articleList += '</li>';
    });
    $('ul.article_list').html(articleList);
    var articleLength = $('ul.article_list > li').length;
    if (articleLength) {
    $('.article_list').show();
    }
    });
    });

     

    Copy this HTML code and paste on your section_page.hbs :

    <div class="articles_list">
    <h3>All Articles</h3>
    <ul class="article_list"></ul>
    </div>

     

    Add this jQeury library on your document_head.hbs :

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

     

    I hope it will help you :)

    Thanks 

    Team

     

    1
  • Kyle B

    Thanks for the suggestion. Technically that worked, but it put them all in one list. I wanted to keep the 2 columns with bullets. I'm sure I could figure out how to do that, but I will have to attempt this another day. It's at least something that works, I just have to make it pretty. Thanks for the help!

    0
  • Ifra Saqlain
    Community Moderator

    Great that it worked! You need some CSS code for making it pretty with two columns and bulleted list and that's not a big issue. You can do that easily.

    0
  • Kyle B

    I took a deeper look. It looks like it doesn't give me the proper articles. I added the code and am seeing a bunch of articles, but they are from random sections. I only want to see all articles that are in that specific section to show. 

    I don't know if I'm explaining myself properly. I have multiple categories and multiple sections within those categories. when you click on a category, you are presented with sections. If you click on a section, I want all of that section's articles to show in a list. So if that section has 5 articles, it will show 5. If it has 50, it will show 50. 

    0
  • Jim Davenport

    Hey Kyle B

    Zendesk limits the number of article that are displayed by default (either displaying a "View all articles" link or pagination links).  To get around this you'd need custom JavaScript to 1) fetch and 2) present the data.

    There are a few things to consider, most importantly:

    • You'd want to fetch articles by section using the REST API, using the section ID made available on the page through the Zendesk page template.
    • When fetching the data from the REST API you may, depending on the number of articles, need to account for pagination as you can only get 100 at a time.
    • You'd need to decide how to present the data you get back. You could render a list using JavaScript, for example, but you'd also need to add custom CSS as previously mentioned.

    Incidentally we've created a few plugins to dynamically generate lists of categories, sections and/or articles anywhere in the Help Center for this type of use-case as part of our Zendesk theme customization framework.  

    0

Vous devez vous connecter pour laisser un commentaire.

Réalisé par Zendesk