Calculate total page count and use for pagination