Php Wordpress插件-按帖子数量对用户进行排名
我想为wordpress创建一个简单的插件,根据用户帖子的数量对用户进行排名。我已经有了这个代码,我不知道如何对数组排序 并将其显示在表中Php Wordpress插件-按帖子数量对用户进行排名,php,mysql,wordpress,plugins,Php,Mysql,Wordpress,Plugins,我想为wordpress创建一个简单的插件,根据用户帖子的数量对用户进行排名。我已经有了这个代码,我不知道如何对数组排序 并将其显示在表中 global $wpdb; $result = count_users(); $users = $result['total_users']; for($id = 1;$id<$users;$id++){ $result = $wpdb->get_results("SELECT wp_users.ID, wp_users.displ
global $wpdb;
$result = count_users();
$users = $result['total_users'];
for($id = 1;$id<$users;$id++){
$result = $wpdb->get_results("SELECT wp_users.ID, wp_users.display_name, COUNT(wp_posts.post_author) AS 'Number_of_posts'
FROM wp_users INNER JOIN wp_posts ON wp_users.ID = wp_posts.post_author
WHERE wp_posts.post_type = 'post'
AND wp_users.ID = $id", ARRAY_A);
}
global$wpdb;
$result=count_users();
$users=$result['total_users'];
对于($id=1;$idget_results)(“选择wp_users.id,wp_users.display_name,将(wp_posts.post_author)计数为'Number_of_posts'
从wp_用户内部加入wp_用户上的wp_帖子。ID=wp_帖子。帖子作者
其中wp_posts.post_type='post'
和wp_users.ID=$ID“,数组A);
}
PHP中的数组排序:
您可以迭代WPDB对象,执行所需的任何逻辑,并将值放入关联数组中
在html表中显示数组中的数据如下所示:
<table>
<tr>
<th>Rank</th>
<th>Username</th>
<th>Post Count</th>
</tr>
<?php
$i = 1;
foreach($array as $value){?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $value['user']; ?></td>
<td><?php echo $value['posts']; ?></td>
</tr>
<?php
$i++;
} ?>
</table>
等级
用户名
员额计数