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.

Category-level stickies

edited December 2010 in Vanilla 2.0 - 2.8
Is is possible to make a sticky only stay at the top in its category? I'm planning a large forum, and the stickies will quickly flood the discussion list.

If it isn't currently possible, I might tackle it as my first plugin for Vanilla. Without digging into the internals yet, it sounds like the best way to implement it would be to set up a new table of "super stickies", suppress normal stickies from showing on the main discussion list, and then displaying "super stickies" on the main list. There would then be a corresponding new permission of "super sticky" to dole out appropriately. Is this the right way to go about it, and is it something reasonable to tackle having to experience in Vanilla?

Comments

  • Yes, stickies are called announcements. Check them out.

    Regarding super-stickies, you would have to develop that yourself.

    /cd
  • LincLinc Detroit Admin
    edited December 2010
    @Lyndsy I'd be very interested in that plugin if you made it.
  • This would make a lot of sense.

    Displaying all announcements across all categories when displaying all discussions means that the use of announcements as "stickies" to describe features of the category falls down completely.
  • judgejjudgej
    edited December 2010
    Just as a side-note, I will be doing a small customisation to display the description of a category along with the category when it is displayed. The names without the descriptions just don't tell people enough, and announcements cannot be used as "stickies" traditionally would have been (also to provide notes for users of the category) for the above reasons (i.e. the announcements leak out of the categories they are attached to).

    That may offer something of what you are trying to achieve.
  • This seemed absurdly simple, so I'm sure I'm missing something with my first glance at the codebase. In /applications/vanilla/controllers/class.discussionscontroller.php, I replaced the following lines:

    $this->AnnounceData = $Page == 0 ? $DiscussionModel->GetAnnouncements() : FALSE; $this->SetData('Announcements', $this->AnnounceData !== FALSE ? $this->AnnounceData : array(), TRUE);

    with

    $this->SetData('Announcements', array());

    If I understand what's going on here, those two lines are a special handling clause for displaying all stickies on the homepage. Take that out, and hard-code the default handling condition, and now I've got no stickies on my homepage.

    This solves 1/2 my issue, but obviously doesn't give me the ability to write home-page stickies. Before I tackle that (which will require adding a table or adding a column to the existing discussions table), I've got to figure out how to package it as a plugin instead of hacking the core.
  • LincLinc Detroit Admin
    @Lyndsy I'd definitely just add a column to the Discussions table, but you seem to be on the right track. :)
  • The announcements are displayed by applications/vanilla/views/discussions/discussions.php which can be copied to themes/{your-theme}/vanilla/views/discussions/discussions.php and edited.

    In that view, which will be protected from core vanilla upgrades, you can add conditions to determine when to display the announcements. That view is run from the categories controller or the discussions controller, depending on whether a category is selected.
  • Ah, I gotchya. Instead of intercepting the data at the controller level, I can go ahead and let it get passed to the view, but choose not to display it. There might be a (very) slight performance hit there, but since views are part of the theming system for Vanilla, doing it that way means that I can do it without losing the ability to update from the trunk.
  • LincLinc Detroit Admin
    Yeah I wouldn't bother trying to prevent the announcements query. The performance gain would be minimal. Once we get caching rocking that's where you'll see big improvements.
  • judgejjudgej
    edited December 2010
    Exactly. I've just done that myself, and it looks like this (in the view I mentioned, discussions.php):

    /* JDJ: do not display announcements unless we are in a category, ie the category under which the announcements are posted. */ if (!empty($this->Category)) { $Alt = ''; if (property_exists($this, 'AnnounceData') && is_object($this->AnnounceData)) { foreach ($this->AnnounceData->Result() as $Discussion) { $Alt = $Alt == ' Alt' ? '' : ' Alt'; WriteDiscussion($Discussion, $this, $Session, $Alt); } } }

    I have just wrapped an if-statement around the loop that displays the announcements at the top. To be honest, it now makes a lot more sense to the users now, as the announcements are all in context.

    If there is a way to label announcements as front-page types, then instead of the condition wrapping the whole list, you could check each announcement in turn to see if it is relevant, i.e. if no category is selected, then only display announcements with the "front page" flag set, otherwise only display announcements without the flag set.

    As a really quick hack, you could check for a certain keyword or tag in the announcement title or body to indicate that it should appear on the front page. That would involve no other changes to the code or database.
  • Might make sense to have an sticky/announcement be global only if it is in a specific category e.g. the category with its id=1
  • Did anyone find an elegant solution for this, or is the above code the best option?

  • ToddTodd Chief Product Officer Vanilla Staff

    This is how the announce popup looks in 2.1.

Sign In or Register to comment.