• I have a plugin that is applied to every single page on my wordpress blog. I only want it on those pages where the comments are enabled/open. So when the comments are closed, the plugin will not be applied to that page. The plugin I’m dealing with is Top 10, which adds a visit counter to each page.

    I have tried the following script:
    <?php if ( comments_open() ) : ?>

    <?php else : // Comments are closed ?>
    <?php endif; ?>

    I put the script around the script that counts the views, but it doesn’t seem to work. This is kinda hard to explain, but I hope you know what I mean. If not, you can just ask 🙂

    Thank you in advance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • http://codex.wordpress.org/Function_Reference/comments_open

    where the script is, it might not automatically ‘know’ the $post_id:

    try:

    <?php global $post;
    if ( comments_open($post->ID) ) : ?>
    
    <?php else : // Comments are closed ?>
    <?php endif; ?>
    Thread Starter peterspliid

    (@peterspliid)

    Doesn’t seem to work, same as before, it disables the script even when the comments are open. Any suggestions?

    I get the following error in the error log as well

    [06-Sep-2010 14:19:53] PHP Fatal error: Call to undefined function comments_open() in /home1/savingst/public_html/gamemust/wp-content/plugins/top-10/top-10-addcount.js.php on line 2

    Not sure you should edit the top-10-addcount.js.php file, instead update the content filter function in top-10.php file, here..

    // Function to add count to content
    function tptn_pc_content($content) {
    	global $single, $post,$tptn_url,$tptn_path;
    	$tptn_settings = tptn_read_options();
    	$id = intval($post->ID);
    
    	if((is_single())&&($tptn_settings['add_to_content'])) {
    		$output = '<script type="text/javascript" src="'.$tptn_url.'/top-10-counter.js.php?top_ten_id='.$id.'"></script>';
    		return $content.$output;
    	} elseif((is_page())&&($tptn_settings['count_on_pages'])) {
    		$output = '<script type="text/javascript" src="'.$tptn_url.'/top-10-counter.js.php?top_ten_id='.$id.'"></script>';
    		return $content.$output;
    	} else {
    		return $content;
    	}
    }

    Try something like..

    // Function to add count to content
    function tptn_pc_content($content) {
    	global $single, $post,$tptn_url,$tptn_path;
    	$tptn_settings = tptn_read_options();
    	$id = intval($post->ID);
    
    	if((is_single())&&($tptn_settings['add_to_content'])) {
    		$output = '<script type="text/javascript" src="'.$tptn_url.'/top-10-counter.js.php?top_ten_id='.$id.'"></script>';
    		return $content.$output;
    	} elseif( is_page() && $tptn_settings['count_on_pages'] && comments_open( $id ) ) {
    		$output = '<script type="text/javascript" src="'.$tptn_url.'/top-10-counter.js.php?top_ten_id='.$id.'"></script>';
    		return $content.$output;
    	} else {
    		return $content;
    	}
    }

    Do note, this code will get removed when the plugin gets an update..

    Hope that helps all the same… 😉

    Thread Starter peterspliid

    (@peterspliid)

    Thank you very much, this is very helpful. Now it doesn’t show the count on pages where the comments are closed, which gets me one step further.

    However, it still counts the visits on all pages, which means that when I create a list that shows ‘most visited pages’, the pages with comments closed are still shown. So how do I prevent the plugin to count visits on pages which have the comments closed?

    Thanks again!

    I’m really not sure, the previous suggestion was easy by looking at the code…

    For the count problem i can’t tell by looking, might need updates all over the place..

    This ideally is something you should ask the author for help with, he(or she) knows the code a great deal better then i do..

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to disable plugin on pages where comments are disabled?’ is closed to new replies.