Skip to:
Content
Pages
Categories
Search
Top
Bottom

Can I take away the comments box from one category only?


  • rossagrant
    Participant

    @rossagrant

    Hi guys,
    I just want to exclude the ability for members to comment on a post from just ONE category.
    Is that possible?
    Thanks
    Ross :)

Viewing 7 replies - 1 through 7 (of 7 total)
  • It should be. Check the WP codes dev docs functions page for category functions, you would need one that returns a posts category then you could run an if not this category display comment reply form


    Roger Coathup
    Participant

    @rogercoathup

    https://codex.wordpress.org/The_Loop#Style_Posts_From_Some_Category_Differently

    @rossagrant – these Codex pages on the loop are your ‘bread and butter’ when theming with WordPress blogs.


    Boris
    Participant

    @travel-junkie

    in single.php something like this should work:

    `<?php if( ! in_category('exclude') )
    comments_template(); ?>`

    where you change exclude to the name or id of the category you don’t want the comments to show up.

    There you go that is the approach written for you, however do check the codex and docs because they are written for a purpose, to help with this sort of request, quick check there first, will likely get you halfway to a solution we can then fill the rest in if necessary.


    rossagrant
    Participant

    @rossagrant

    @travel-junkie

    Thanks so much for the code, i’ve just given it a try but I’m getting a blank page when trying to look at the post’s page.

    <?php if( ! in_category('61') )
    comments_template(); ?>

    Category 61 is the one I want to disable comments on so I used the above code. Is that all I needed to put in single.php or is there anything else?

    Sorry for sounding so crap, but… I am!

    Oh yeah, any progress on the CV plugin? Can’t wait to start using it!
    Thanks

    @hnla @rogercoathup Thanks for your help here too guys! :)

    How did you write it as the category name? as travel-junkie shows? it should work on a single post page in or outside the loop.

    Blank page suggests a critical error in php syntax somewhere.

    You might need to show the snippet of code you added


    Boris
    Participant

    @travel-junkie

    Well, you probably want to adjust all the index files like index.php, archive.php or category.php as well, so the comment count doesn’t show up there when the post is in that category. When you use the category ID then you need to get rid of the enclosing ‘.

    So that would be
    `<?php if( ! in_category( 61 ) )
    comments_template(); ?>`

    The jobboard plugin is quite stable now and I’ll release that soon, so shortly after that I’ll work on getting the CV component ready.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Can I take away the comments box from one category only?’ is closed to new replies.
Skip to toolbar