Let visitors post comments on category page

I’m looking for a way to let users comment categories on category.php, but I haven’t been able to find one. Simple pasting didn’t do the trick (didn’t really expect it to.)

For clarification, I’m not looking for users to comment posts in category.php, but rather to comment the category itself. Is it possible?

Related posts

Leave a Reply

4 comments

  1. Short answer: No, it is impossible, if we are talking about WP way, because it was not provided by WP architecture.

    It could be done if you create your own plugin (or implement it as a part of theme). To do it you need to create custom table and implement logic for saving comments and displaying comments.

  2. This isn’t possible out of the box because WordPress can only handle comments on posts, in the broad sense which includes pages, custom post types, etc.

    Because a category is a group of posts rather than a post per se, there’s no built-in functionality to attach comments to a category.

    If you have relatively few categories, you could create a page for each category. Have them use a custom page template including a custom loop to get the category members, and including a comments form.

    You can redirect standard category links to this page using the ‘category_link’ filter.

  3. Create a custom page
    With your own customized loop
    Enable comments on that page.

    It won’t have the same Url.

    It can be done with the same url and the original -without custom tables- wp-comment system but it’s much harder.
    If you want that ask and I’ll look into it.

  4. It’s not possible with the default comment system of WordPress

    In order to print the comment form, you have to put the function comments_template() inside your category.php template file.

    Unfortunally, this function “will not display the comments template if not on single post or page, or if the post does not have comments”.

    Solution with a third-party comment system (e.g Disqus)

    If you use an other comment system, it is very likely that this system does not take into account the WordPress structure (pages, posts, categories, etc.), but instead relies only on URLs: each site URL can have its own stream of comments.

    For example, if you have Disqus installed on your blog, you could create a category.php file like this one:

    <?php get_header(); ?>
    
    <div id="content">
    
        <?php if ( have_posts() ) : ?>
    
            <header class="archive-header">
                <h1 class="archive-title">Category: <?php single_cat_title( '', false ); ?></h1>        
                <?php if ( category_description() ) : ?>
                    <div class="archive-meta"><?php echo category_description(); ?></div>
                <?php endif; ?>
            </header>
    
            <?php while ( have_posts() ) : the_post(); ?>       
                <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
                <div class="entry">
                    <?php the_content(); ?>
                </div>
            <?php endwhile;
    
        else: ?>
    
            <p>Sorry, no posts matched your criteria.</p>
    
        <?php endif; ?>
    
        <h2>Comments</h2>
    
        <div id="disqus_thread"></div>
        <script>
            /**
             *  RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
             *  LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables
             */
            /*
            var disqus_config = function () {
                this.page.url = PAGE_URL;  // Replace PAGE_URL with your page's canonical URL variable
                this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
            };
            */
            (function() {  // DON'T EDIT BELOW THIS LINE
                var d = document, s = d.createElement('script');
    
                s.src = '//EXAMPLE.disqus.com/embed.js';
    
                s.setAttribute('data-timestamp', +new Date());
                (d.head || d.body).appendChild(s);
            })();
        </script>
        <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    
    </div>
    
    <?php get_footer(); ?>
    

    I created the template from the one suggested in How to Create Category Templates in WordPress; I added the comments using the snippet suggested in Manually install Disqus on WordPress.

    The code is tested on my own website and it works.