Skip to content

Instantly share code, notes, and snippets.

@wub
Forked from surrealroad/Fetch Discourse Topics
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wub/c1e2476bbe5ce1d69dbd to your computer and use it in GitHub Desktop.
Save wub/c1e2476bbe5ce1d69dbd to your computer and use it in GitHub Desktop.
// Usage
var forumURL = 'http://forums.com';
$('#discourse-latest-container').getDiscourseTopics(forumURL, 'latest');
// Fetch latest topics
(function($) {
jQuery.fn.getDiscourseTopics = function (url, page) {
if ($(this).exists()) {
$.getJSON(url + '/' + page + '.json', function (data) {
var topics = data.topic_list.topics,
limit = 6,
result = '<nav>';
for (var i = 0; i < limit; i++) {
result += '<a href="' + url + '/t/' + (topics[i].slug) + '/' + (topics[i].id) + '">';
result += '<span class="badge">' + (topics[i].posts_count) + '</span>';
result += '<h5>' + (topics[i].fancy_title) + '</h5>';
result += '</a>';
}
result += '</nav>';
$(this).html(result);
});
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment