def paginate(*args)
options = args.pop
page, per_page, total_entries = wp_parse_options(options)
finder = (options[:finder] || 'find').to_s
if finder == 'find'
total_entries ||= (Array === args.first and args.first.size)
args.unshift(:all) if args.empty?
end
WillPaginate::Collection.create(page, per_page, total_entries) do |pager|
count_options = options.except :page, :per_page, :total_entries, :finder
find_options = count_options.except(:count).update(:offset => pager.offset, :limit => pager.per_page)
args << find_options
pager.replace(send(finder, *args) { |*a| yield(*a) if block_given? })
pager.total_entries = wp_count(count_options, args, finder) unless pager.total_entries
end
end