I run a multiple author site and I have created a plugin in wp-admin where authors can connect and collaborate with each other. To enhance it, I want to display a list of latest posts, this list should look like this:
As the picture shows, the list should contain the latest 10 posts with the Username, the post title linked and when it was posted (either how long ago or the exact time of post).
The HTML for this should be:
<table class="widefat">
<thead><tr><th scope="col">User</th><th scope="col">Post</th><th scope="col">Time</th></tr></thead>
<tfoot><tr><th scope="col">User</th><th scope="col">Post</th><th scope="col">Time</th></tr></tfoot>
<tbody>
<tr>
<td title="Username">Username</td>
<td><a href="URL">Post title</a></td>
<td title="2012-11-07 16:16:37">8 hours ago</td>
</tr>
</tbody>
</table>
How can I create a list like this? Note that this list will be used in wp-admin only.
All you need is a table with
class='widefat'
andget_posts()
. Then you run through the results (if there are any) and print the table rows.Here is a very simple example as a dashboard widget. Note the lack of I18n â it is not ready to use!
Result