Moved posts_db_query to libs.
Minor modifications to existing code, general cleaning.
Changed template to match dev/live db switching.