-
-
Save wub/c1e2476bbe5ce1d69dbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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