search
HomeCMS TutorialWordPressThe whole process of WordPress theme creation (10): making comments.php

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:

<h3 id="Comments">Comments</h3>
<div> </div>
<ol>
<li>
<div> <img  alt="The whole process of WordPress theme creation (10): making comments.php" > <a>Reply</a> </div>
<div>
<div> <cite><a>Joe Bloggs</a></cite>
<div>January 6, 2010 at 6:26 am</div>
</div>
<div>
<p>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.</p>
</div>
</div>
</li>
</ol>
<div> </div>

Add a comment

 
  • Add comment 

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

<?php  comments_template(); ?>

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:

<?php if (isset($_SERVER[&#39;SCRIPT_FILENAME&#39;]) && &#39;comments.php&#39; == basename($_SERVER[&#39;SCRIPT_FILENAME&#39;]))
die (&#39;Please do not load this page directly. Thanks!&#39;);
?>

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


  •  The whole process of WordPress theme creation (10): making comments.php Reply 
     Joe Bloggs
    January 6, 2010 at 6:26 am

    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.

  • Change to :

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

    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 

    and change it to:

    <?php  
    if ( !comments_open() ) :
    // If registration required and not logged in.
    elseif ( get_option(&#39;comment_registration&#39;) && !is_user_logged_in() ) : 
    ?>
    <p>你必须 <a>">登录</a> 才能发表评论.</p>
    <?php  else  : ?>
    <!-- Comment Form -->
    
    /wp-comments-post.php" method="post">     

    发表评论

        
     
        
                       
    •                          " size="23" tabindex="1" />         
    •         
    •                          " size="23" tabindex="2" />         
    •         
    •                          " size="23" tabindex="3" />         
    •                  
    • 您已登录:/wp-admin/profile.php">" title="退出登录">退出 »
    •                  
    •                                   
    •         
    •                          发表评论 
    •     
             ID); ?>

    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!

    Statement
    This article is reproduced at:ludou. If there is any infringement, please contact admin@php.cn delete
    How to easily move your blog from WordPress.com to WordPress.orgHow to easily move your blog from WordPress.com to WordPress.orgApr 18, 2025 am 11:33 AM

    Do you want to move your blog from WordPress.com to WordPress.org? Many beginners start with WordPress.com but quickly realize their limitations and want to switch to the self-hosted WordPress.org platform. In this step-by-step guide, we will show you how to properly move your blog from WordPress.com to WordPress.org. Why migrate from WordPress.com to WordPress.org? WordPress.com allows anyone to create an account

    How to Automate WordPress and Social Media with IFTTT (and more)How to Automate WordPress and Social Media with IFTTT (and more)Apr 18, 2025 am 11:27 AM

    Are you looking for ways to automate your WordPress website and social media accounts? With automation, you will be able to automatically share your WordPress blog posts or updates on Facebook, Twitter, LinkedIn, Instagram and more. In this article, we will show you how to easily automate WordPress and social media using IFTTT, Zapier, and Uncanny Automator. Why Automate WordPress and Social Media? Automate your WordPre

    How to Fix Custom Menu Item Limits in WordPressHow to Fix Custom Menu Item Limits in WordPressApr 18, 2025 am 11:18 AM

    Just a few days ago, one of our users reported an unusual problem. The problem is that he reaches the limit of custom menu items. Any content he saves after reaching the menu item limit will not be saved at all. We've never heard of this issue, so we decided to give it a try on our local installation. More than 200 menu items were created and saved. The effect is very good. Move 100 items to the drop-down list and save them very well. Then we knew it had to do with the server. After further research, it seems that many others have encountered the same problem. After digging deeper, we found a trac ticket ( #14134 ) that highlighted this issue. Read very

    How to add custom metafields to custom classification in WordPressHow to add custom metafields to custom classification in WordPressApr 18, 2025 am 11:11 AM

    Do you need to add custom metafields to custom taxonomy in WordPress? Custom taxonomy allows you to organize content besides categories and tags. Sometimes it is useful to add other fields to describe them. In this article, we will show you how to add other metafields to the taxonomy they create. When should custom metafields be added to custom taxonomy? When you create new content on your WordPress site, you can organize it using two default taxonomy (category and tag). Some websites benefit from the use of custom taxonomy. These allow you to sort content in other ways. For example,

    How to Remotely Publish to WordPress using Windows Live WriterHow to Remotely Publish to WordPress using Windows Live WriterApr 18, 2025 am 11:02 AM

    Windows live writer is a versatile tool that allows you to post posts directly from your desktop to your WordPress blog. This means you don't need to log in to the WordPress admin panel to update your blog at all. In this tutorial, I will show you how to enable desktop publishing for your WordPress blog using Windows Live Writer. How to set up Windows Live Writer on WordPress Step 1: To use Windows Live Writer in WordPr

    How to Fix White Text and Missing Buttons in WordPress Visual EditorHow to Fix White Text and Missing Buttons in WordPress Visual EditorApr 18, 2025 am 10:52 AM

    Recently, one of our users reported a very strange installation problem. When writing a post, they can’t see anything they write. Because the text in the post editor is white. What's more, all the visual editor buttons are missing, and the ability to switch from visual to HTML doesn't work either. In this article, we will show you how to fix the white text and missing button issues in the WordPress visual editor. Be a Beginner Note: If you are looking for hidden buttons that may be seen in screenshots of other websites, you may be looking for a kitchen sink. You have to click on the kitchen sink icon to see other options such as underline, copy from word, etc.

    How to display avatar in user email in WordPressHow to display avatar in user email in WordPressApr 18, 2025 am 10:51 AM

    Do you want to display avatars in user emails in WordPress? Gravatar is a network service that connects a user's email address to an online avatar. WordPress automatically displays visitors’ profile pictures in the comments section, but you may also want to add them to other areas of the site. In this article, we will show you how to display avatars in user emails in WordPress. What is Gravatar and why should I display it? Gravatar stands for globally recognized avatars, which allows people to link images to their email addresses. If the website supports

    How to change the default media upload location in WordPressHow to change the default media upload location in WordPressApr 18, 2025 am 10:47 AM

    Do you want to change the default media upload location in WordPress? Moving media files to other folders can improve website speed and performance and help you create backups faster. It also gives you the freedom to organize your files in the way that suits you best. In this article, we will show you how to change the default media upload location in WordPress. Why change the default media upload location? By default, WordPress stores all images and other media files in the /wp-content/uploads/ folder. In this folder you will find children of different years and months

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    1 months agoBy尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. Best Graphic Settings
    1 months agoBy尊渡假赌尊渡假赌尊渡假赌
    Will R.E.P.O. Have Crossplay?
    1 months agoBy尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    Atom editor mac version download

    Atom editor mac version download

    The most popular open source editor

    MantisBT

    MantisBT

    Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use