Home > CMS Tutorial > WordPress > body text

The whole process of WordPress theme creation (10): making comments.php

藏色散人
Release: 2023-02-21 10:12:30
forward
1648 people have browsed it

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~

The whole process of WordPress theme creation (10): making comments.php

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

 
  1.   
     Joe Bloggs

    Donec leo. Aliquam risus elit, luctus vel, interdum vitae, malesuada eget, elit. Nulla vitae ipsum. Donec ligula ante, bibendum sit amet, elementum quis, viverra eu, ante. Fusce tincidunt. Mauris pellentesque, arcu eget feugiat accumsan, ipsum mi molestie orci, ut pulvinar sapien lorem nec dui.

 

Add a comment

 
  • Add comment 
Copy after login

Add the code in the original location of single.php:

Copy after login

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:

Copy after login

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):

  •   
     Joe Bloggs

    Donec leo. Aliquam risus elit, luctus vel, interdum vitae, malesuada eget, elit. Nulla vitae ipsum. Donec ligula ante, bibendum sit amet, elementum quis, viverra eu, ante. Fusce tincidunt. Mauris pellentesque, arcu eget feugiat accumsan, ipsum mi molestie orci, ut pulvinar sapien lorem nec dui.

  • Copy after login

    Change to :

    post_password) && $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) { 
            // if there's a password
            // and it doesn't match the cookie
        ?>
        
  •         

    请输入密码再查看评论内容.

        
  •          
  •         

    评论功能已经关闭!

        
  •          
  •         

    还没有任何评论,你来说两句吧

        
  •     
    Copy after login

    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; ?>
       
  •     '回复','depth' => $depth, 'max_depth' => $args['max_depth']))) ?> 
    %s'), get_comment_author_link()); ?>    
    comment_approved == '0') : ?> 你的评论正在审核,稍后会显示出来!
                 
  • Copy after login

    WordPress functions used in the above code and corresponding descriptions:

    Link to reply to the messageget_comment_author_linkUsed to get the commenter’s blog addressget_comment_time Get the comment publishing time##edit_comment_linkcomment_text()Okay, now it can be displayed normally at the bottom of your article page Commented! Now we continue to create a form for submitting comments. Delete the following code (that is, the code of the comment form):
    Function name Function function
    get_avatar($comment, 48) Get the commenter’s gravatar avatar, the size is 48 * 48
    ##comment_reply_link()
    The link for the administrator to modify the comment
    Output comment content
    
    

    Add a comment

     
    • Add comment 
    Copy after login

    and change it to:

    
    

    你必须 登录 才能发表评论.

        

    发表评论

        
     
        
                       
    •                                   
    •         
    •                                   
    •         
    •                                   
    •                  
    • 您已登录:退出 »
    •                  
    •                                   
    •         
    •                          发表评论 
    •     
             ID); ?>
    Copy after login

    function Name##is_user_logged_inwp_login_url##get_comment_author_linkRead the cookie and automatically help the user fill in the user name if the user has posted a comment before##$ comment_author_emailRead cookie, if the user has posted a comment before, it will automatically help the user fill in Email$comment_author_urlRead 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 reservewp_logout_urlLogout linkWordPress Tutorial》
    Function
    Determine whether the user is logged in
    Blog login address
    Used to get the commenter’s blog address $comment_author
    Recommended learning: "

    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!

    Related labels:
    source:ludou.org
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!