Simplify the first post and last post generation

Previously the first post and last post generation code, hard coded
directly on main.html.php, now moved to functions.php.