Skip to content

Instantly share code, notes, and snippets.

@primozcigler
Last active August 29, 2015 14:22
Show Gist options
  • Save primozcigler/678b74c1e0262a1d4cb7 to your computer and use it in GitHub Desktop.
Save primozcigler/678b74c1e0262a1d4cb7 to your computer and use it in GitHub Desktop.
Using Zendesk API for article in multiple sections
// fix to display general questions in themes' sections
// using Zendesk API
// @link https://developer.zendesk.com/rest_api/docs/help_center/articles#list-articles
(function() {
if ( $( '.breadcrumbs a[href*="200506781"]' ).length ) { // 200506781 is ID of the section for general questions
var config = {
$articleList: $( 'ul.article-list' ),
tmpl: _.template( '<li><a href="<%= url %>"><%- title %></a></li>' ),
apiUrl: 'https://proteusthemes.zendesk.com/api/v2/help_center/sections/200132421/articles.json',
};
var appendArticles = function( data ) {
_.each( data.articles, addArticle );
};
var addArticle = function( article ) {
config.$articleList.append( config.tmpl( {
title: article.title,
url: article.html_url,
} ) );
};
$.get( config.apiUrl, '', appendArticles );
}
})();
// hide dummyhide articles - if section has 0 articles fix
(function() {
$( '.article-list a[href*="dummyhide"]' ).parent().remove();
})();
@kalico1
Copy link

kalico1 commented Aug 14, 2015

This is really exciting...would love to test it out. You mentioned writing a tutorial....any timeline for getting that done? I think I can piece it together from what you've said, but....stuff happens. ;-)

@starr321000
Copy link

HI Primoz,

Thanks very much for putting this together. Wondering if you might have time for a question? I am getting an "Unexpected token ILLEGAL" error on line 8 when trying to implement it with my Zendesk instance. Any ideas what the issue could be?

Thanks,
Starr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment