cleanup code, update for correct permalink and also introduce bpmag_search_query, add support for fallback template