我正在尝试显示特定节点类型“
的一天总计数function bootstrap_subtheme_get_node_count($content_type) {
$time = strtotime('yesterday midnight');
$query = "SELECT COUNT(*) amount FROM {node} n ".
"WHERE n.type = :type and n.created => " . $time;
$result = db_query($query, array(':type' => $content_type))->fetch();
return $result->amount;
}
并打印
<?php bootstrap_subtheme_get_node_count('page'); ?>
请纠正我的错误?
答案 0 :(得分:0)
您的代码看起来不错,请进行2次更改
1:使用类型创建更改。
2:从count(*)中删除*符号并根据需要添加nid或其他列名称,这有利于查询性能。
代码示例:
function bootstrap_subtheme_get_node_count($content_type) {
$time = strtotime('yesterday midnight');
$query = "SELECT COUNT(nid) amount FROM {node} n ".
"WHERE n.type = :type and n.created => :created";
$result = db_query($query, array(':type' => $content_type,
':created' => $time))->fetch();
return $result->amount;
}