Fixed thread and post order

Re-wrote some of the sql queries to return the posts and threads in the
right order. It also updates the queries to add the thread's last post
created at and last post username.