Some methods to optimize guest comment in WordPress

Source: Internet
Author: User
This article mainly introduces some optimizations to the guest comment function in WordPress, including displaying the welcome information on the comment, for more information, see the comments provided by a Blog (with the name and URL forgotten) in the next few days. after a visitor leaves a message, the data input box is hidden, as if he had logged on. visitors can choose to modify relevant information before commenting. provide visitors with a good user experience. today, I transplanted this feature to my own topic. it is not difficult to create it. let's share it.

Requirement

Careful friends may have noticed that when you access this Blog again after posting a comment on a WordPress, you do not need to fill in the materials because they are already in the materials input box. if you have not commented on the data or cleared the Cookie, the data input box is empty.

1. when the visitor's data already exists, the visitor pays little attention to the data itself, and the data input boxes will become "out of sight". we need to find a way to hide the data. at the same time, we need to display the guest name, otherwise he/she does not know his/her identity.

2. A visitor may change his or her email address or want to change the name of the cool point. at this time, he/she must want to change the information. therefore, some measures are required to allow visitors to re-view the data input box.

3. visitors who have never provided any information must see the data input box.

Analysis

We can see from the demand that we are dealing with visitors in two states: those with data and those without data.
If you have materials, you can select either the data input box (display nickname) or the hidden data input box (display nickname.
The visitor without data only displays the data input box (no nickname.
Well, we have two buttons (change and cancel) for the visitor with the data, one for displaying the data input box and the other for hiding it.

Ideas

1. how to write a page? Before coding, we should take a look at the clues. use pseudo code.

If (visitor with information ){
Place Guest nickname
Place change button (after clicking: Hide change button, show cancel button, show data input box)
Place the cancel button (click the button to display the Change button, hide the cancel button, and hide the data input box)
}
Data placement input box
If (visitor with information ){
Hide cancel button
Hide data input box
}
2. how do I know if a visitor has commented? As mentioned above, the comment on the visitor's information will be displayed. that is to say, the method for obtaining the information has been implemented in the code. let's look for it...

 

It is it! $ Comment_author is the nickname of a visitor. when it is empty, it indicates that the visitor information is empty.

3. some controls are displayed and hidden. how can this problem be solved? We don't need to jump to the page for this purpose. use JavaScript. we can write a method to set whether some controls are displayed or not, just a very simple method:

/*** Set the display style of the control * @ param id control ID * @ param status Control Display status (''for display and 'none' for hiding ') */function setStyleDisplay (id, status) {document. getElementById (id ). style. display = status ;}

Encoding

What should I do next? You can probably write code. view my...

 <? Php if ($ comment_author! = ""):?>
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.