get_var("select meta.meta_value from $wpdb->posts p left join $wpdb->postmeta meta on p.ID = meta.post_id where p.ID=$id"); $link_type = 'absolute'; // check if the redirect link starts with blog home url (absolute link) if( ! ( strstr ($redirect_link, get_bloginfo('home')) ) ) { // $start = strpos($redirect_link, '/'); // print("starts with: [".$start."]"); // check of starts with slash -> relative link if((0==strpos($redirect_link, '/') )) { $link_type = 'relative'; } else { // else - it is not a link to our website // comments are off print $none; return; } } // get stub $post_stub = get_stub_of_url($redirect_link); // if stub finishes with slash, remove it $sql = "select ID from $wpdb->posts where post_name like'%$post_stub'"; $redirect_post_id = $wpdb->get_var($sql); // print($sql); // no such article - some kind of error (in link perhaps) // show that the comments are off if($redirect_post_id == null) { print $none; return; } // else - show regular comments else if (! is_single() && ! is_page()) { if ( !isset($comment_count_cache[$redirect_post_id]) ) $comment_count_cache[$redirect_post_id] = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = $redirect_post_id AND comment_approved = '1';"); $number = $comment_count_cache[$redirect_post_id]; if (0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status) { echo $none; return; } else { if (!empty($post->post_password)) { // if there's a password if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie echo(__('Enter your password to view comments')); return; } } echo ''; // hack needed due to absurd wordpress API global $id; $old_id = $id; $id = $redirect_post_id; comments_number($zero, $one, $more, $number); $id = $old_id; echo ''; } } } function get_stub_of_url($url) { $stub = ''; if($debug) { print("link=[".$url."]"); print("
"); } // remove params $start_params = strrchr ($url, '?'); if($debug) { print("start_params=[".$start_params."]"); print("
"); } if($start_params!=null) $stub = str_replace( $start_params, "",$url); else $stub = $url; if($debug) { print("stub=[".$stub."]"); print("
"); } // check if last character is a slash, if so, remove it if($stub[strlen($stub)-1]=='/') { $stub = substr($stub, 0, strlen($stub)-1); } $stub = substr(strrchr($stub, "/"), 1); if($debug) { print("stub=[".$stub."]"); print("
"); } return $stub; } ?>