Theme Help: Always display author name instead of last commenter
I'd like to modify my theme to always display the thread author's name (linked to his/her profile). I'm struggling to find a way to do this in my themehook file. I know I can overwrite functions, but in order to change this bit I'd need to overwrite the writeDiscussion() function in /views/discussions/helper_file.php which is a very large function and seems like a bad idea to mess with.
So in my themehook file I currently have:
public function DiscussionsController_AfterDiscussionTitle_Handler($Sender) { if ($Sender->EventArguments['NewDiscussionModule']) { $Discussion = $Sender->EventArguments['Discussion']; $First = $Sender->EventArguments['Discussion']->FirstName; } }
While that gets me the name, I am not sure how to make it a link. If I can get the name as a link then I can just insert that and hide the existing last commenter stuff with css. However, if that idea isn't the best way to go about this then let me know.
I also thought about using FirstName and the User ID to create the url myself but that feels dirty too. I'd like to use something like the userAnchor() function but it seems to be out of scope in this context.
Any help is appreciated. Thanks!
Comments
@yourfavorite
I'm a bit confused.
Where do you want this to happen?
Vanilla displays the author name on the category page by default, as well as the name of the person who last commented.
I can't see what you want to achieve.
@whu606 Currently it is setup to display the author of the post only if there are no comments. If there are comments then the author of the post is replaced by the last comment author. I would like to always display the author of the post.
Ultimately though, I need to change the HTML structure a bit to achieve what I want in my responsive design. Ideally that chunk of HTML would be a chunk of template code or something, but instead it is baked into a php file.
This is the final structure I need to achieve for instances of listings of posts (all categories page, category page)
Sorry for the oddly formatted code. I don't know how to post HTML on here without all my HTML tags going invisible in between the pre tags.
I really can't see what you want to achieve or where you want to achieve it.
Are you talking about what is shown on the www.yourforum.com/discussions page?
What theme are you using?
Perhaps you could post a screen-shot?
1) This applies to /discussions as well as /category/category-name
2) I am building a custom theme from scratch.
This is what my theme currently looks like. Note how the first post says "Most recent by Casey" while the second post says "Started by Casey". Vanilla is setup to always display the most recent comment author here. So in the case of a new discussion with no comments, it defaults to the author of the discussion.
http://imgur.com/I2FsiMr
What I want my theme to look like when I am done is below. Note that it always displays the discussion author below the title, not the most recent commenter. It also displays the number of comments and the most recent commenter on the right side.
http://imgur.com/7mWFicF
In order to achieve this, I need the HTML structure to match what I posted above.
Regardless of what exactly I'm trying to do, the ultimate question is this:
What is the best method for altering the structure of the HTML for an individual discussion in a list of discussions (such as on /discussions)?
Currently the best way I know to do this is to copy the writeDiscussion() method (which is over 100 lines of code) from /views/discussions/helper_file.php and modify it within my theme hook file. This seems awfully dirty and less than ideal. I'm hoping for a better solution.
That would make the purpose of notifying that there is a new comment and by whom obsolete.
The idea of having that information visible is so people can decide if they want to go read the new comment by someone.
If you do not want the info displayed, but want to keep the knowledge of who posted, use the plugin IndexPhotos which always follows the OP in the discussions list. Then hide the other info with css or a theme hook.
Editing or cloning core files is never recommended.
The images you posted for what you want it to look like, are not from a vanilla forum are they ?
There are $Configurations that can change the order of comments , ascending or descending the same with discussions, but that will not change, as far as I know, to just say Started by.
What you probably want is to have both show ?
Started by X and also Most Recent in order to look like your second image.
Adding the Started by x might be possible using a theme hook or a plugin. It would simply call the name of the original author to be added to the meta info.
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
@vrijvlinder I understand the purpose of always displaying the most recent commenter. However there are instances where the OP is more important in making that decision. One example might be a forum where people are critiquing designs. I'd argue that who posted the work is more important than who most recently critiqued.
I'm aware that editing or cloning core files is never recommended and I'd like to avoid it but I can't seem to find a better option for doing what I want at the moment. So my plan is to just copy the writeDiscussion() function over to my themehook file and modify it there.
The first image I posted is from my WIP Vanilla theme. The second image I posted is from a prototype of a forum I built before deciding on using Vanilla. Now I'm working on tweaking vanilla to match the prototype I built.
The current plan is to have both show, yes. And I believe I could get this to happen using certain Events to trigger. However the bigger issue here is how to modify markup structure when it is baked into php files.
I'm having a hard time understanding why there isn't better separation of logic from markup in vanilla but I'm going to work around it as best I can for now. I'm sure as I progress I will have more instances where I need to modify the markup pieces of Vanilla. If more of the markup were separated from PHP, likely none of this would be a problem.
You do not need to modify core files for style. You would use css for that.
The reason why the entire thing is in php is because the output is dynamic and thus is easier to use because it sets variables instead of having to write thousands of lines of html if the content were static.
This makes it easier not harder. If it is harder to you , your approach is wrong.
Then what you need to do is find the code that makes it be Started by , and then create a simple plugin to inject it to the meta info for the discussion on top of what already is...
? Not sure I understand this ... that is the whole purpose of having templates
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
RE: Separation of logic and markup.
But there aren't templates for the most part. There's a ton of HTML inside of the helper_file.php for any given view. The only real template I see is the master template. And that template doesn't offer a lot of flexibility to individual parts of the page. I understand the dynamic nature of these pages but based on what I've seen in these helper files, a bunch of the HTML could be removed from these files and placed into template files with minimal logic that pull in variables. The variables are defined in the helper files.
RE: Only needing CSS to change style.
This is only moderately true. I also need to modify the layout. Markup becomes especially important when dealing with responsive design. I assure you that a lot of the styling/layout I need to do cannot be accomplished with purely CSS based on the current HTML markup in Vanilla.
And I say that is not possible. Because You CAN use only css or theme hooks or plugins to change the layout. You simply have not been capable and are looking for other ways...
You can clone views and modules and add them to your theme and edit them as you see fit to change the layout ... No need to edit the helper files... Try Harder!!
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
I will start by saying sorry for the novel to follow.
I know that I can accomplish everything with css/themehooks/plugins but I don't see a very clean way to do it. All of this would be much easier if Vanilla had more separation between HTML and logic files.
My current options as far as I know: (Please let me know if there are better ones)
1) I could inject a whole bunch of my own HTML via an Event and then hide Vanilla's elements via CSS. Duplicate info hidden with CSS in the HTML is sloppy and not ideal. Not to mention I have to rewrite a bunch of code that is handled very well within Vanilla but is out of scope for my themehooks file (ie - userAnchor()). I believe there may be ways around the scope issue, but I'm not familiar.
2) I can inject small pieces of HTML as needed. Injecting an opening tag at one event and a closing tag at another event but this can get very confusing and cumbersome to maintain.
3) I can duplicate the entire helper_functions.php file into my theme and modify as needed. This seems like the worst option since updates to helper_functions.php in future versions would be hard to keep track of.
4) Lastly, and the option I'm moving forward with for now, is that I can duplicate the specific function from within helper_functions.php into my themehooks file after the themehook class closing bracket (In this case, writeDiscussion()). This is similar to the previous option but at least I am only overwriting individual functions as needed.
There are certain layout tasks that require specific HTML structure. This is especially true for responsive layouts. I may be newer to Vanilla but I understand HTML and CSS quite well. It is not a matter of trying harder. Without modifying the HTML I would have to make sacrifices to my design and layout and I'd rather not do that.
If you take a look through the files within the views/discussions/ you will see that the bulk of the HTML is inside of the helper_functions.php file. The rest of the files barely have any HTML in them other than the larger elements that wrap the detailed information and actual content. If you want control over the detailed information and pieces within a view, much of it is baked into these helper_functions.php files.
I know that you have a lot of experience with Vanilla. Do you know of any themes that are a rather drastic visual departure from the default Vanilla themes and are fully responsive? I've been looking for examples of other themes that I can learn from but most of them are just minor re-skins of the existing Vanilla structure. Most of them just change colors, spacing, etc.
Below is roughly the final look I am trying to achieve. (Note there are some things in this prototype that don't apply to Vanilla feature wise). Feel free to scale your browser in and note how things shift and change. I know nothing here looks super outlandish but I assure you there are nuances to alignment and centering and positioning that require certain HTML structure to achieve responsively.
http://caseybritt.com/clients/2014/tr42/category.php
Sidenote: Thus far I've been referring to helper_functions.php as helper_file.php. Sorry if that has caused in confusion.
Sounds all sane and logical to me. If you want to create a complete new look and also have a small and lean html code, you have to rewrite something.
I do not see more possibilities than you have listed and to me, creating your own writeDiscussion() function is the only real solution here. Everything else is either not what you want or just "too much".
In order not to break plugin functionality, you should keep every
$Sender->EventArguments...
and make sure you use every$Sender->fireEvent...
at the appropriate place in your code.I would copy the function, comment out what you do not need and insert what you like to see. That way, you might be able to see differences between your version and upcoming versions.
Generally: I once had to look at a software that used smarty templates for every smallest piece of code. While it was very, very, very flexible it was always very, very, very hard to find where the info I needed was hiding. It's always a trade off.
Coming back to that question: userAnchor isn't out of scope, but it expects a user object, not the name. See how it is used in writeDiscussion():
$First = UserBuilder($Discussion, 'First');
You would be able to do so in
public function DiscussionsController_AfterDiscussionTitle_Handler
as well.Thanks for the confirmation @R_J I'll keep moving forward with my existing plan then!
Also, my bad on userAnchor. I didn't bother checking the logs. Only saw the error when I tried to use it and assumed out of scope. My b! I will be sure to give it another shot if needed.
There are few things you mentioned that rang a bell:
1. Showing author - I successfully use the ShowDiscussionAuthor plugin to always show the author. Very convenient.
If that is all you wanted than the above and css work would be easier to implement.