Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

How to have original post at top of all comments pages?

If I go to a thread, the original post is shown at the top with the comments underneath. However, if there are enough comments to have multiple pages, if I go to Page 2 or 3 etc, the original post is no longer shown at the top.

I'd like the original post to stay at the top for all comment pages. The reason for this is that if somebody lands on Page 2+, they may not see what the original discussion was about without clicking back through to Page 1.

Is this something that can be easily done?

Many Thanks!

Comments

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    If you are not able to code, then it will not be possible at all: there is no setting for this.

    If you are not afraid of a new experience, then look at the developer documentation, get yourself the example plugin from GitHub and ask here for support when you get stuck:

    https://docs.vanillaforums.com/developer/addons/
    https://github.com/vanilla/addons/tree/master/plugins/example

  • Thanks for the quick reply. I'm not afraid to code (but I'm no expert!), I used to run a myBB forum and heavily customised the php - though Vanilla appears to have a different set up, using tpl templates etc. I'll have a poke around and see what I can do.

  • With this caveat in mind .... https://open.vanillaforums.com/discussion/28297/help-with-views
    ...and having read how to create a view in your template's folder ...

    You might also be able to the safer accomplish this via a simple theme hook.

    In any way proceed ...

    Copy this file
    /applications/vanilla/views/discussion/index.php

    to
    /themes/yourtheme/views/discussion/index.php

    Change

    // Write the initial discussion.
    if ($this->data('Page') == 1) {
        include $this->fetchViewLocation('discussion', 'discussion');
        echo '</div>'; // close discussion wrap
    
        $this->fireEvent('AfterDiscussion');
    } else {
        echo '</div>'; // close discussion wrap
    }
    

    to

    // Write the initial discussion.
    // if ($this->data('Page') == 1) {
        include $this->fetchViewLocation('discussion', 'discussion');
        // echo '</div>'; // close discussion wrap
    
        $this->fireEvent('AfterDiscussion');
    // } else {
        echo '</div>'; // close discussion wrap
    // }
    
  • You can also, install InfiniteScroll and you won't have this issue :)
    https://open.vanillaforums.com/addon/infinitescroll-plugin

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    I also started with MyBB! But you have to understand that extending Vanillas functionality is always done by adding files, not by changing existing ones.

    Create a plugin in the plugin folder and only work with the files in this folder.

    In Vanillas source code you find many "fireEvent" calls and whenever you see something like that, you can get control!

    The file which is building a discussion is here https://github.com/vanilla/vanilla/blob/release/2.6/applications/vanilla/views/discussion/index.php

    And in there, this part is most interesting:

    $this->fireEvent('AfterPageTitle');
    // Write the initial discussion.
    if ($this->data('Page') == 1) {
        include $this->fetchViewLocation('discussion', 'discussion');
        echo '</div>'; // close discussion wrap
        $this->fireEvent('AfterDiscussion');
    } else {
        echo '</div>'; // close discussion wrap
    }
    

    If you have created your own plugin, add this method to it:

    public function discussionController_afterPageTitle_handler($sender) {
        echo '<h1>test</h1>';
    }
    

    It might help you understand what is happening (after you have read the developer documentation)

    After that, think about the code above:
    "If this is page one, print out discussion, if not print a closing div".

    Your method now should check the same and if this is page one, you do not have to do anything, but if this is not page one, you should take the above actions.

    A few hints on that:

    • $this is passed to your method as first element and is refenced with the word $sender by convention
    • if you want to fetViewLocation from a plugin, you need to use it like that: include $sender->fetchViewLocation('discussion', 'discussions', 'vanilla')
    • you shouldn't echo that closing div, because that will be done by the if clause from above anyway
    • don't forget to fire the AfterDiscussion event. Otherwise some additions made by other plugins will not work on the discussions that are printed out by you. You can emit that event like that $sender->fireAs('DiscussionController')->fireEvent(AfterDiscussion');
    donshakespeare
  • Thanks to all above for the advice. Managed to do what I needed to do and now also have a better understanding of how Vanilla is set up compared to myBB for example

    R_Jrbrahmson
Sign In or Register to comment.