Last active
March 6, 2016 17:12
-
-
Save surrealroad/6990268 to your computer and use it in GitHub Desktop.
jQuery snippet to grab latest discourse forum posts and display them inside a container
uses TBS classes
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 discourse items | |
(function($) { | |
jQuery.fn.getDiscourseTopics = function (url, page) { | |
// load forum topics | |
if($(this).exists()) { | |
$this = $(this); | |
$.getJSON(url + "/" + page + ".json", function (data) { | |
var topics = data.topic_list.topics; | |
//console.log(topics); //uncomment this for debug | |
var limit = 6; // topics.length; | |
var result = '<nav class="list-group list-group-flush">'; | |
for (var i = 0; i < limit; i++) { | |
result += '<a class="list-group-item" href="' + url + '/t/' + (topics[i].slug) + '/' + (topics[i].id) + '"><span class="badge">' + (topics[i].posts_count) + '</span> <h5>' + (topics[i].fancy_title) + '</h5></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
Any tutorial or example on how to use it as it's not working for me :(