Original posters within a category list

סיכום מבוסס בינה מלאכותית

In a support category discussion titled ‘Original posters within a category list,’ pw3010 seeks help modifying the Feverbee theme to display original poster avatars instead of the latest poster’s in a category’s latest topic list. They note that the category JSON doesn’t include original poster data, making the task challenging. awesomerobot provides a code solution: modifying the topicListThree section to fetch user data via /latest.json?order=posts&ascending=true, then mapping each topic’s posters to their user objects. They also advise updating the template to use {{topic.posters.[0].user.username}} instead of {{topic.last_poster_username}} to display the original poster’s avatar. pw3010 confirms the solution works, crediting awesomerobot for helping them complete the implementation.

I’m using the Feverbee by @pfaffman template as a basis for my customisations, and I’ve come up against an issue that I can’t find a solution for after much searching of the forums. The following section in my example contains the latest 3 entries from a specific category:

However, I can’t seem to change the user images to be those of the original poster, rather than the latest. I don’t think that information is passed by the category json, and I’m stumped in trying to add it.

I need to make this change as the latest poster may have been a member of our support staff, rather than someone who needs help.

Right so you need to pull in the users… you can edit the topicListThree section to:

  ajax("/latest.json?order=posts&ascending=true").then (function(result){
                     topicListThree = [];
                    var usersThree = result.users;
                    result.topic_list.topics.slice(0,3).forEach(function(topic){
                        topic.posters.forEach(function(poster){
                            poster.user = $.grep(usersThree, function(e){ return e.id == poster.user_id; })[0];
                        });
                        topicListThree.push(Topic.create(topic));
                    });
                    component.set('topicListThree', topicListThree);
                });

and then in the template you can replace the {{topic.last_poster_username}} part of the img src with {{topic.posters.[0].user.username}}

Amazing, thanks @awesomerobot. I’d got 2/3 of the way there but needed the assistance to get over the line!