• I am developing a custom theme. I do not currently have a comments.php file, but WordPress appears to be using some sort of default for comments. I really like this one, but want to tweak a few things about it.

    How can I create my own comments.php which is basically a copy of the WordPress one?

Viewing 15 replies - 1 through 15 (of 27 total)
  • Start with “comments.php” from TwentyTen.

    Thread Starter mrtsherman

    (@mrtsherman)

    Thanks Chip. I took a look into that one, but it does not function like the default one at all. I have also already styled the comment form and I am loathe to redo all that work with a replacement comments.php. I feel as though I should just be able to copy and paste the commenting code from the default section into the custom section. But I don’t know where the code is coming from!

    Thanks Chip. I took a look into that one, but it does not function like the default one at all.

    What do you mean? The TwentyTen Theme is the default Theme.

    I have also already styled the comment form and I am loathe to redo all that work with a replacement comments.php.

    You are, of course, welcome not to do so. But in so doing, your Theme will become less and less future-proof, and you will be missing out on a lot of comment-form related functionality.

    I feel as though I should just be able to copy and paste the commenting code from the default section into the custom section. But I don’t know where the code is coming from!

    Your template files call the commenting system via the comments_template() template tag.

    This template tag requires a template file called “comments.php”.

    All of your custom comment code needs to be in the “comments.php” file, whether you choose to implement the core features/markup, or roll your own.

    Thread Starter mrtsherman

    (@mrtsherman)

    Thanks for the help. I realize my question didn’t make a ton of sense because I am pretty new to WordPress and very new to custom theming. No choice though.

    Your words made me remember that I added comments to my custom theme by inserting comments_template( '', true ); into my single.php file. So I guess what I really need to do is modify whatever functions comments_template calls to get the styling differences I want.

    So I guess what I really need to do is modify whatever functions comments_template calls to get the styling differences I want.

    Not exactly.

    What you need to do is provide a “comments.php” file, which is called – and required – by the comments_template() template tag.

    Commenting functionality in WordPress really simply will not work correctly unless you provide these two elements together: the comments_template() template tag, and the “comments.php” template file.

    Thread Starter mrtsherman

    (@mrtsherman)

    Commenting functionality in WordPress really simply will not work correctly unless you provide these two elements together: the comments_template() template tag, and the “comments.php” template file.

    Interesting. Oddly, with no comments.php my comments look and work great. Once I specify a comments.php with nothing in it all my comments disappear. I don’t understand why it works without it.

    So I guess the answer is that if I want to customize comments then I must have a comments.php file and I must code it up myself. No piggybacking on whatever I am currently using.

    Interesting. Oddly, with no comments.php my comments look and work great. Once I specify a comments.php with nothing in it all my comments disappear. I don’t understand why it works without it.

    This is known as “legacy support”, in which certain template functions will use the specified template file from the default Theme if not provided by the currently active Theme.

    This functionality, however, is deprecated, and will be removed soon. So I wouldn’t rely on it.

    Thread Starter mrtsherman

    (@mrtsherman)

    AHA – a find all on my wordpress directory led me to wordpress\wp-includes\theme-compat\comments.php which is what was being used by default in the absence of my own. Copied that into my theme directory and now I can make my modifications. Thank-you for leading me in the correct direction Chip. Nice suit gravatar with greenery in the background too =)

    If you are just going to copy/paste code to use as a basis for further modification, I would strongly recommend using the “comments.php” file from TwentyTen, rather than the deprecated “comments.php” in theme-compat.

    If you need to make modifications to the comment-reply form, we can help you learn how to do so in a forward-compatible manner, using the comment_form() function.

    Thread Starter mrtsherman

    (@mrtsherman)

    If you need to make modifications to the comment-reply form, we can help you learn how to do so in a forward-compatible manner

    Where would I go to get help with this? Start a new thread, use this one?

    I am interested in knowing why the current method I am using is a bad idea while the twenty ten is a good idea.

    This thread is fine. 🙂

    The current method you’re using uses deprecated (old) code.

    Among other things, TwentyTen uses the comment_form() function, which will be critical to future-proofing your Theme. Plugins will rely on the hooks provided by this function. Core features may rely on the hooks provided by this function. Any future core security enhancements will rely on the existence of this function.

    Thread Starter mrtsherman

    (@mrtsherman)

    I will start mucking around with twentyten theme. Looks like I need comments.php as well as twentyten_comment from the functions.php file. Hopefully this won’t be too rough. I will post back as I have questions. Thanks again.

    Thread Starter mrtsherman

    (@mrtsherman)

    So not sure what to do. I copied over the twenty ten commenting theme, but I still can’t figure out how the thing works. At this point I think I would be fine starting from scratch. Are there any good examples out there that get all the basics up and going?

    You don’t actually have to use the comment callback function from TwentyTen.

    If you need something a bit more simple (I don’t perform any callbbacks on wp_list_comments() or comment_form(), you can take a look at what I use in the latest version of my Theme:
    http://themes.svn.wordpress.org/oenology/1.1/comments.php

    (I’ve not done much with it lately, so I might need to touch it up in places; nevertheless, it might provide a good alternate example for you.)

    Thread Starter mrtsherman

    (@mrtsherman)

    This template is good. Quite straightforward and easier to get through than the twentyten template. Say I wanted to edit the following section though:

    Your email address will not be published. Required fields are marked *

    Where is this content coming from?

Viewing 15 replies - 1 through 15 (of 27 total)
  • The topic ‘Copy default WordPress comments code’ is closed to new replies.