📜 ⬆️ ⬇️

Pleasant commenting

Hi, Habrahabr!

I want to tell a small, but very useful technique that allows you to remember data (name, e-mail, website) when commenting.


The principle of this technique


The Wordpress blog engine has an excellent built-in function of storing data when commenting, but few use it, because they often do not know all the subtleties of the layout for Wordpress.
So, we will check whether the data entered and on the basis of this test, we will leave or remove unnecessary forms.
')

Technical implementation


The data is stored in cookies (cookies), get a value, for example, the name can be using the variable $comment_author .

Actually, the code itself with comments, we add it, or rather, even edit our own for this format, in the comments.php file:

  <! - Check the value of $ comment_author: empty or not empty ->

 <? php if ($ comment_author == "")
 {
 ?>
 <! - Forms are visible, $ comment_author is empty ->
 <input type = "Text" tabindex = "2" name = "author" value = "Your name *"> 
 <input type = "Text" tabindex = "3" name = "email" value = "Email *"> 
 <input type = "Text" tabindex = "4" name = "url" value = "Your site">

 <? php} else {?>
 <! - $ comment_author - filled, forms are hidden ->

 Glad to see you again <b> <? Php echo $ comment_author;  ?> </ b>.  You do not need to fill in anything.

 <! - Change input type to hidden to hide it ->

 <input type = "hidden" name = "author" value = "<? php echo $ comment_author;?>" />
 <input type = "hidden" name = "email" value = "<? php echo $ comment_author_email;?>" />
 <input type = "hidden" name = "url" value = "<? php echo $ comment_author_url;?>" />
 <? php}?>
 <! - Do not forget to delete comments -> 

This is actually the whole trick, a simple example, but terribly useful.

You can also add a button to exit (delete cookies), but for personal blogs this is not critical.

Thanks to all! See you! ;-)

The source of this trick (code highlighting)

Source: https://habr.com/ru/post/37842/


All Articles