• Resolved Icethrill

    (@icethrill)


    Hey! I am trying to figure out how I can disable comments if they are relatives to a category. I want to check if any categories you choose for a post is a relative to a certain grandparent category named “Publications”.

    At the moment I am using the theme thematic. Anyone knows? I don’t really want the customer to be having to add Closed comments everytime when he makes a post for a publication.

    Is there an easy way to do this?

Viewing 1 replies (of 1 total)
  • Thread Starter Icethrill

    (@icethrill)

    This was easier than I thought…

    $cat = get_category_by_path(get_query_var('category_name'),false);
    $cat2 = $cat->cat_ID;
    
    $cat1 = 54;
    
    $ancestor_to_cat = cat_is_ancestor_of( $cat1, $cat2 );

    Then put an if-case before the comments loop in single.php. If anyone else had the same problem as me.

    $cat1 = category relatives ID you want to test against
    $cat2 = the category that is connected to the post

    $ancestor_to_cat = either true or false. A boolean value.

    if(!$ancestor_to_cat){ ?>
    
    	<?php thematic_comments_template(); ?>
    
    <?php } ?>

    This is the thematic-themes single.php. So just wrap the if case around the whole comments in any single.php and it should work just fine.

Viewing 1 replies (of 1 total)
  • The topic ‘Disabling comments on certain posts’ is closed to new replies.