I introduced you to "The whole process of WordPress theme production (9): Making single.php". This article continues to introduce to you how to make comments.php. Let's take a look at it together~
Today we will make the comment module of the comment theme. Create a new comments.php under the theme directory Aurelius, cut the following code in single.php, and paste it into comments.php:
Comments
![]()
Add the code in the original location of single.php:
The above statement The function is to import all the contents in comments.php into single.php, which has the same effect as writing the code in comments.php directly in single.php.
For the sake of security, to prevent malicious users from opening the comment file directly, please add the following code in the comments.php header:
Because the comment code output by WordPress's output comment function wp_list_comments() Different from the comment code of our theme, we have to customize our comment list and delete the following code in comments.php (the following code is used to list all comments on the article):
Change to :
post_password) && $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) { // if there's a password // and it doesn't match the cookie ?>
You can roughly see the meaning of the above code, which is a lot of if... then..., if the above conditions are not met, all comments will be listed. Now change the ?> in functions.php in the theme folder Aurelius to the following code. If the functions.php you downloaded from this blog before already has the following code, there is no need to add it:
function aurelius_comment($comment, $args, $depth) { $GLOBALS['comment'] = $comment; ?>
WordPress functions used in the above code and corresponding descriptions:
Function name | Function function |
get_avatar($comment, 48) | Get the commenter’s gravatar avatar, the size is 48 * 48 |
##comment_reply_link() | Link to reply to the message|
Used to get the commenter’s blog address | |
Get the comment publishing time | |
The link for the administrator to modify the comment | |
Output comment content |
and change it to:
你必须 登录 才能发表评论.
Function | |
Determine whether the user is logged in | |
Blog login address | ##get_comment_author_link |
Used to get the commenter’s blog address | $comment_author |
##$ comment_author_email | Read cookie, if the user has posted a comment before, it will automatically help the user fill in Email |
$comment_author_url | Read cookie, if If the user has made a comment before, it will automatically help the user fill in the blog address |
do_action('comment_form', $post->ID); | This function is a Some plug-ins reserve |
wp_logout_url | Logout link |
Recommended learning: " | WordPress Tutorial
The above is the detailed content of The whole process of WordPress theme creation (10): making comments.php. For more information, please follow other related articles on the PHP Chinese website!