As a result, I got such a script, maybe it will be useful to someone.
const Theme = {} const user = require.main.require('./src/user') const privileges = require.main.require('./src/privileges') Theme.getUsersByCategory = async function(data) { const { templateData: { cid } } = data const allUserIds = await user.getUidsFromSet('users:joindate', 0, -1) const asyncFilter = async (arr, predicate) => { const results = await Promise.all(arr.map(predicate)) return arr.filter((element, index) => results[index]) } const availableUserIds = await asyncFilter(allUserIds, async (id) => { return await privileges.categories.can('read', cid, id) }) data.templateData.availableUsers = await user.getUsersData(availableUserIds) return data } module.exports = Themehow can I list topics in a category?
-
I want to list topics in a category on a custom page. I want the title, author, data and content to be showed. I basically want all the announcements on the front page. Is there a easy to do this without making a plugin or something?
-
You'll need a plugin. Do you want a custom page, or a category as your homepage? They're done differently.
-
@agarcia17 said:
@yariplus since category as homepage is coming in the next release, thanks to you :), what steps would i have to take in order to have the api also return the main content for each topic in that category?
The change is transparent to the api, a call to yourdomain.com/api will return the category data along with the topics summary, the exact same data you would get if you called yourdomain.com/api/category/1/categoryname
-
@agarcia17 afaik, there is no way to do that with a single call. It does give you the mainPids, so you could do another call to api/post/pid
-
@baris awesome! i didnt notice there was an setting for that! thanks! I will give that a try later on today or tomorrow, but since its only a teaser i will probably need to make a modification on the 'teaser' function to have it return the full post instead, correct?
-
The returned teaser has the below data so you might not need to change anything.
"teaser": { "_key": "post:38335", "pid": 38335, "uid": 2962, "tid": 6400, "content": "<p><a class=\"plugin-mentions-a\" href=\"https://community.nodebb.org/user/baris\">@baris</a> awesome! i didnt notice there was an setting for that! thanks! I will give that a try later on today or tomorrow, but since its only a teaser i will probably need to make a modification on the 'teaser' function to have it return the full post instead, correct?</p>\n", "timestamp": "2015-09-21T17:37:45.565Z", "user": { "_key": "user:2962", "userslug": "agarcia17", "picture": "https://secure.gravatar.com/avatar/3839aee901d7adc05ac204b75074989d?size=128&default=mm&rating=pg", "username": "agarcia17", "uid": 2962 }, "index": 9 }