如果您使用的是核心簡檔模塊,你可以使用類似下面。它將顯示正在被查看的用戶所創建的節點。作爲一個額外的好處,它只需要執行一個自定義數據庫查詢。
插入此片段爲template.php
在你的主題文件夾,並改變「THEMENAME」你的主題名稱:現在
function THEMENAME_preprocess_user_profile(&$variables) {
// Information about user profile being viewed
$account = $variables['account'];
// Get info on all content types
$content_types = node_get_types('names');
// Get node counts for all content types for current user
$stats = array();
$node_counts = db_query('SELECT type, COUNT(type) AS num FROM {node} WHERE status = 1 AND uid = %d GROUP BY type', $account->uid);
while ($row = db_fetch_array($node_counts)) {
$stats[] = array(
'name' => $content_types[$row['type']],
'type' => $row['type'],
'num' => $row['num'],
);
}
$variables['node_stats'] = $stats;
}
,在user-profile.tpl.php
可以添加類似的東西:
// If user has created content, display stats
<?php if (count($node_stats) > 0): ?>
// For each content type, display a DIV with name and number of nodes
<?php foreach ($node_stats as $value): ?>
<div><?php print $value['name']; ?> (<?php print $value['num']; ?>)</div>
<?php endforeach; ?>
// Message to show for user that hasn't created any content
<?php else: ?>
<?php print $account->name; ?> has not created any content.
<?php endif; ?>
這只是你可以做的一般想法。您還可以爲您查找/顯示的內容類型添加限制,檢查用戶的權限以查看這些統計信息,使用CSS更改統計信息的外觀等。
如果您使用的是Content Profile,則可以使用THEMENAME_preprocess_node()
並檢查節點執行此代碼前有配置文件節點。