为此制作一个自定义模块应该不难。
统计模块运行的查询是:
db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), arg(1));
// If we affected 0 rows, this is the first time viewing the node.
if (!db_affected_rows()) {
// We must create a new row to store counters for the new node.
db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', arg(1), time());
}
我们唯一需要做的就是将arg(1) 替换为我们想要添加计数的节点ID,这可以在类似这样的自定义模块中完成。
function custom_module_menu() {
$items['custom/ajax/%node'] = array(
'title' => 'Update count',
'page callback' => 'custom_module_update_counter',
'page arguments' => array(2),
'access callback' => array('custom_module_access_control'),
);
function custom_module_update_counter($node) {
db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), $node->nid);
// If we affected 0 rows, this is the first time viewing the node.
if (!db_affected_rows()) {
// We must create a new row to store counters for the new node.
db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', $node->nid, time());
}
}
剩下的就是实现一个自定义的访问控制函数,你可以检查请求是ajax还是做任何你喜欢的控制,函数必须只返回TRUE或FALSE。您还需要在您的设置中使用节点 ID 创建一个 ajax 事件,但这也不应该太难。
您需要点击 url custom/ajax/2 来更新 id 为 2 等的节点。