Get topics in category?

  • Hi everyone,

    I have try write widget to get topics in category (1,2,3) and show it in theme, but I dont know hot to get query to this widget.

    Pls advice,

    Many thanks

  • I want to know too~

    Have you or anyone else solved this ?

  • Community Rep

    Use jQuery to get the topics from the API.

    <div id="mycats"></div>
    $.getJSON('/api/category/1', function (data) {
      for (var i in data.topics) {
        $('#mycats').append('<div>' + data.topics[i].title + '</div>')

  • @yariplus it would be better to make it in the server-side ?

  • Community Rep

    It would, technically. You would have to make your own widget plugin to add the data to the widget template, or add a widget to widget-essentials. Using Categories.getCategoryTopics

    psuedo example, check out widget-essentials for all needed code.

    Plugin.renderMyTopicsWidget = function(widget, callback) {
        cid: widget.req.params.cid || 1, // or whatever category ID you want.
        set: 'cid:' + widget.req.params.cid + ':tids',
        reverse: true,
        start: 0,
        stop: 10,
        uid: widget.uid
      }, function(err, result) { = result
        app.render('widgets/yourwidget',, function(err, html) {
          translator.translate(html, function(translatedHTML) {
            callback(err, translatedHTML)


    <!-- BEGIN topics -->
    <!-- END topics -->

  • @yariplus cool, got it , thanks ~!



Looks like your connection to NodeBB was lost, please wait while we try to reconnect.