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! = ""):?>