COUNT(*), pagination, elseif for templates