Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Sort categorie layout by date newest post in categorie
thomas_tim
New
Hey,
I'm running vanilla 2.0.18.8 and I've got a question regarding the categorie layout. I use that layout but I would like that te top categorie is the categorie with the newest post in it, and right now it is alphabetically. Is there anyway to do this or would I have to make the code for it myself? Thanks!
Tagged:
0
Comments
Hi @thomas_tim: This feature is not implemented and i guess that it will not be on the list of the Vanilla Team. This is something that needs to be coded, maybe some DEVs here can give you a glimpse into how much work this could get.
Btw.: What aspect are you trying to achieve, how will this interact with your community?
Thank @phreak for you answer. I'm making a forum for students during the finals so they can post questions and discuss answers. But because there are over 20 categories in the categories/discussions (I think this gives a quick, but structured layout) it some times requires a lot of scrolling.
I think I will code it myself then, what is the best way to make this mergeable in the project? Create a new layout, or something else?
@thomas_tim: I'd really like to see how this can be achieved with either a plugin or a custom view (not that I'd use it, but I'm interested in how this technically can be achieved)
You can use this as a workaround:
Add this CSS to your theme and only new discussions are displayed in categories/discussions. But it is only an ugly workaround...
Are you looking to modify the
/categories/all
page or the/categories/discussions
page?Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
@R_J When I was setting up my community, I though it would be cool to sort categories by freshness.
But believe me, it would be hell for user. Its a bad UX practice to keep shuffling blocks.
For your community, I would suggest categories in hierarchical order with root categories as headings
There was an error rendering this rich post.
Exactly what I was thinking. One minute the category is at the bottom of the page the next minute it is at the top. It would be a nightmare to navigate.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
@aery: thanks and I'm sure you're right with your suggestion. If I will ever start my own community, I'll go with just 4 categories. Having to scroll up and down all the time doesn't sound as if it could
But I'm really interested at the technical aspect of a solution for the question. I've taken a look at the categories views and controllers and I can only think of
I do not know how to do any of this three and I could have learned something ;-)
I think it can be easily done with javascript.
There was an error rendering this rich post.
What follows are my thoughts on how I would approach modifying the
categories/all
view to sort by the most recent.Since we don't care about the existing hierarchy inherent in the category model, I would get a list of the categories, iterate through it, request the latest discussion in that category, pop the entire category and discussion onto a list, then sort by the insert/update date on the discussion.
You could probably just change the category structure right before rendering the view if you were clever about it.
I agree with others that this sounds like a bad idea.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Because this forum is used during the finals to discuss topics there are usually only three topics active at the time, and it's really annoying if they are the ones at the bottom. I just want to try and see how it goes, because at the moment it is far from ideal as well, and I think this makes it easier to see what topics are "fresh".
We really like the categories view, so we don't want to lose that but we would like it to make it easier to see which categories are active. Maybe a average insert date of the latest 5 posts in that categorie? That would make it shift around a lot less and still have the fresh categories on top.
The monster below gives you the sort order you've thought of. You'll have to test it though, because my test installation hasn't got enough categories ;-)
You'd have to copy the view
/vanilla/views/categories/all.php
to/themes/yourtheme/views/categories/all.php
and before line 23foreach ($this->CategoryData->Result() as $Category) {
you'd have to either change the sort order or use another syntax for the loop in order to change the view according to your needs.From performance aspects, this SQL is a nightmare. I do not know how caching is done in the Garden framework, but if this SQL is executed everytime someone calls the view, I'd say you will have to face complains from your users...
You can think of writing a plugin which updates a yet-to-be-created-category-order-info-field after each new discussion, so that this query only has to be called one time per new discussion and not one time per view.
I still wouldn't do it:
1. if the categories of interest are everytime the same, you should thinking about changing their general order so that they are always displayed at the top
2. you could even change the sort order manually just for the playoffs
3. also subgrouping them as aery suggested is still an option.
Categories aren't sorted alphabetically, as far as I know. You can change their order manually under http://www.yourforum.com/vanilla/settings/managecategories simply by drag'n'drop
views are not the place to put complicated logic or queries.
How to find the latest comment or discussion? the categories module, categories/all and categories/discussions all use
CategoryModel->GetFull()
, which mean it is already joined (via denormalisedLastDiscussionID
, andLastCommentID
), you could useCategoryModel_AfterGetFullQuery_Handler
to specify the order.grep is your friend.
note the above won't work becuase OrderBy is already employed after this point.
$CategoryData = $this->SQL->OrderBy('TreeLeft', 'asc')->Get();
meaning according the the query builder the order by clause would be something like
ORDER BY d.DateInserted DESC, co.DateInserted DESC, TreeLeft ASC
However
TreeLeft
needs to be your primary sort to respect hierarchy.As a hack you might think to implement
TreeLeft
first, even though duplicated the final TreeLeft will have little order prevalence. However TreeLeft is always unique, so therefore secondary sorts are irrelevant (categories use the nested set model).This means you have to abandon this idea. Instead of modifying the query, your strategy would be to modify the result. Which mean you have to catch the respective object before they are processed by views, and modules, and then reorder them, respecting hierarchy, then return them as a DataSet.
grep is your friend.