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; ?>
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… 😉
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..