How to only allow logged in users to see comments to discussions?
Hi all!
What is the best way to achieve this? I want to make it so in order to see full comments on a discussion, you need to be a user of the forums. So any visitor can click on discussions and see the discussion itself, but in order to see the comments, they have to create a profile. An important caveat: I still want search engines to be able to index the site.
Thank you!
Best Answer
-
vrijvlinder MVP
Here is what the whole thing would theoretically look like. This is off the top of my head so it could be a red herring but who knows.. But this how you would write a plugin at the most basic level.
<?php if (!defined('APPLICATION')) exit(); // Define the plugin: $PluginInfo['NoComment'] = array( 'Name'=>'NoComment', 'Description' => "This plugin hides comments for guests and prompt them to log in to see them ", 'Version' => '1.0', 'MobileFriendly'=>TRUE, 'Author' => "VrijVlinder", 'License' => 'GNU GPL2' ); class NoComment_Plugin extends Gdn_Plugin { public function Base_Render_Before($Sender) { $Session = Gdn::Session(); // this tests to see is user is logged in or antixst if (!($Session->IsValid())) $Sender->AddCssFile($this->GetResource('design/nocomment.css', FALSE, FALSE)); $Sender->AddJsFile($this->GetResource('js/nocomment.js', FALSE, FALSE)); } else { return; } public function Setup() { } }
You would name this file default.php and pt it in a folder called NoComment
You will create a new file and call it nocomment.css and create a folder inside NoComment folder called design and put this file in there and add the css code above to it.
You will create another file called no comment.js and create another new folder called js and put this file inside of that inside of the NoComment folder.
Put the jquery code above inside the no comment.js file and test to see if it works.
6
Answers
You can create a plugin which checks for valid session to load comments or not. I am not sure if this would have any effect on seo ...
Or you could make a simpler plugin that only hides the comments from view via css.
Then depending on the class names for the CommentsWrap in your theme, you write a css file with this in it .
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
Ah, got it! Okay, how would I display a message that says "In order to see the comments, please log in"?
Anyone else know if this would block search engines from indexing the whole post?
It probably will, search engines are quite smart in figuring out what a user can see and what not.
You could try to exclude bots from this by matching them by User-Agent String
line 4 in vrijvlinders code:
taken from this SO answer: http://stackoverflow.com/a/15047834
You can test if it works with a user agent switcher browser plugin.
My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations
VanillaSkins.com - Plugins, Themes and Graphics for Vanillaforums OS
Note that some people believe changing your site's behavior for bots will negatively affect your SEO mojo.
If you believe in SEO, that is something to know.
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.
Yeah, I definitely don't want to try to trick any bots, so that's good to know.![:) :)](https://open.vanillaforums.com/plugins/emojiextender/emoji/little/smile.png)
So what would the entire script look like to also show a line to prompt people to log in to see the comments?
As you have figured out by now, I'm no coder, so as easy-to-implement as it can be, the better!![;) ;)](https://open.vanillaforums.com/plugins/emojiextender/emoji/little/wink.png)
What would I add to this? Would the line go here?
public function Base_Render_Before($Sender) { $Session = Gdn::Session(); // this tests to see is user is logged in or antixst if (!($Session->IsValid())) $Sender->AddCssFile($this->GetResource('design/hidecomments.css', FALSE, FALSE)); } else { return; <div>DOES IT GO HERE???</div> }
No you could add it as a css content or image text
Or you could use a message and pic after content. You can also echo the message in the code above but need to figure out where we want to echo it.
echo '<span>text goes here</span>';
Could also add the text as jquery which to me mgh be the easiest to append the text and you know where it goes then load the js file along with the css file.
You can also add the log in link to that above
http://css-tricks.com/css-content/
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
Here is what the whole thing would theoretically look like. This is off the top of my head so it could be a red herring but who knows.. But this how you would write a plugin at the most basic level.
You would name this file default.php and pt it in a folder called NoComment
You will create a new file and call it nocomment.css and create a folder inside NoComment folder called design and put this file in there and add the css code above to it.
You will create another file called no comment.js and create another new folder called js and put this file inside of that inside of the NoComment folder.
Put the jquery code above inside the no comment.js file and test to see if it works.
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
to be able to echo the text I think you would use this function
public function Base_BeforeCommentDisplay_Handler($Sender) {
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
You could also try hiding the comments with jQuery, that may even trick some search engines.
Or blur out the comments: http://blurjs.com/
Like quora does it. I hate it when sites do this, though.
My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations
VanillaSkins.com - Plugins, Themes and Graphics for Vanillaforums OS
Yes I hate that too... I think I need glasses even more..![:( :(](https://open.vanillaforums.com/plugins/emojiextender/emoji/little/frown.png)
What I would like to know is how important are comments in searches.. I mean when I search for something like why is my gas tank leaking gas, I get comments not necessarily the discussion title.
Which leads to unsuccessful searches as far as quality content. search bot are stupid and only use words to match what you need. Comments may be gibberish. I would care more about the topic.
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
It is amazing how many ways to skin katzen ... katzen geschinden ? oder gibt es einen anderen weg ?
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
We don't usually skin that many cats here, but we like taking different roads that all lead to rome.
My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations
VanillaSkins.com - Plugins, Themes and Graphics for Vanillaforums OS
You mean in Deutschland or here ? If here, yes , here only de-feather raptor birds...but I would avoid Rome.. it is full of sinners...![;) ;)](https://open.vanillaforums.com/plugins/emojiextender/emoji/little/wink.png)
![>:) >:)](https://open.vanillaforums.com/plugins/emojiextender/emoji/little/naughty.png)
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌