{"action":"created","issue":{"url":"https://api.github.com/repos/timber/timber/issues/1173","repository_url":"https://api.github.com/repos/timber/timber","labels_url":"https://api.github.com/repos/timber/timber/issues/1173/labels{/name}","comments_url":"https://api.github.com/repos/timber/timber/issues/1173/comments","events_url":"https://api.github.com/repos/timber/timber/issues/1173/events","html_url":"https://github.com/timber/timber/pull/1173","id":173471896,"number":1173,"title":"1118 pagination api","user":{"login":"lggorman","id":5794405,"avatar_url":"https://avatars.githubusercontent.com/u/5794405?v=3","gravatar_id":"","url":"https://api.github.com/users/lggorman","html_url":"https://github.com/lggorman","followers_url":"https://api.github.com/users/lggorman/followers","following_url":"https://api.github.com/users/lggorman/following{/other_user}","gists_url":"https://api.github.com/users/lggorman/gists{/gist_id}","starred_url":"https://api.github.com/users/lggorman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lggorman/subscriptions","organizations_url":"https://api.github.com/users/lggorman/orgs","repos_url":"https://api.github.com/users/lggorman/repos","events_url":"https://api.github.com/users/lggorman/events{/privacy}","received_events_url":"https://api.github.com/users/lggorman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"jarednova","id":1298086,"avatar_url":"https://avatars.githubusercontent.com/u/1298086?v=3","gravatar_id":"","url":"https://api.github.com/users/jarednova","html_url":"https://github.com/jarednova","followers_url":"https://api.github.com/users/jarednova/followers","following_url":"https://api.github.com/users/jarednova/following{/other_user}","gists_url":"https://api.github.com/users/jarednova/gists{/gist_id}","starred_url":"https://api.github.com/users/jarednova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jarednova/subscriptions","organizations_url":"https://api.github.com/users/jarednova/orgs","repos_url":"https://api.github.com/users/jarednova/repos","events_url":"https://api.github.com/users/jarednova/events{/privacy}","received_events_url":"https://api.github.com/users/jarednova/received_events","type":"User","site_admin":false},"assignees":[{"login":"jarednova","id":1298086,"avatar_url":"https://avatars.githubusercontent.com/u/1298086?v=3","gravatar_id":"","url":"https://api.github.com/users/jarednova","html_url":"https://github.com/jarednova","followers_url":"https://api.github.com/users/jarednova/followers","following_url":"https://api.github.com/users/jarednova/following{/other_user}","gists_url":"https://api.github.com/users/jarednova/gists{/gist_id}","starred_url":"https://api.github.com/users/jarednova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jarednova/subscriptions","organizations_url":"https://api.github.com/users/jarednova/orgs","repos_url":"https://api.github.com/users/jarednova/repos","events_url":"https://api.github.com/users/jarednova/events{/privacy}","received_events_url":"https://api.github.com/users/jarednova/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/timber/timber/milestones/9","html_url":"https://github.com/timber/timber/milestones/v.1.2.0","labels_url":"https://api.github.com/repos/timber/timber/milestones/9/labels","id":2001362,"number":9,"title":"v.1.2.0","description":"","creator":{"login":"jarednova","id":1298086,"avatar_url":"https://avatars.githubusercontent.com/u/1298086?v=3","gravatar_id":"","url":"https://api.github.com/users/jarednova","html_url":"https://github.com/jarednova","followers_url":"https://api.github.com/users/jarednova/followers","following_url":"https://api.github.com/users/jarednova/following{/other_user}","gists_url":"https://api.github.com/users/jarednova/gists{/gist_id}","starred_url":"https://api.github.com/users/jarednova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jarednova/subscriptions","organizations_url":"https://api.github.com/users/jarednova/orgs","repos_url":"https://api.github.com/users/jarednova/repos","events_url":"https://api.github.com/users/jarednova/events{/privacy}","received_events_url":"https://api.github.com/users/jarednova/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":0,"state":"open","created_at":"2016-09-13T14:59:35Z","updated_at":"2016-09-13T15:00:02Z","due_on":"2016-09-27T00:00:00Z","closed_at":null},"comments":6,"created_at":"2016-08-26T14:51:56Z","updated_at":"2016-09-25T03:23:40Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/timber/timber/pulls/1173","html_url":"https://github.com/timber/timber/pull/1173","diff_url":"https://github.com/timber/timber/pull/1173.diff","patch_url":"https://github.com/timber/timber/pull/1173.patch"},"body":"**Ticket**: #1118 \r\n**Reviewer**: @jarednova \r\n\r\n#### Issue\r\nPagination is generated based on the default query, requiring an extra `query_posts` to make pagination accurate for a custom query.\r\n\r\n#### Solution\r\nSet pagination as a method on the PostsCollection object .  The pagination object associated with the collection will use the same query params used to generate the collection, negating the need to tweak the default query (in order to make this work I've set the PostsCollection to keep a private reference to the wp_query object used to create it).  I've also added a `Timber::get_posts_collection` method to allow for a cleaner way to return a PostsCollection object instead of an array.  \r\n\r\n#### Impact\r\nShould have no effect on existing methods.\r\n\r\n#### Usage\r\n```php\r\n $context['posts'] = Timber::get_posts_collection(); \r\n```\r\n```twig\r\n<ul class=\"pages\">\r\n\t{% for page in posts.pagination.pages %}\r\n\t\t<li>\r\n\t\t\t{% if page.link %}\r\n\t\t\t\t<a href=\"{{page.link}}\" class=\"{{page.class}}\">{{page.title}}</a>\r\n\t\t\t{% else %}\r\n\t\t\t\t<span class=\"{{page.class}}\">{{page.title}}</span>\r\n\t\t\t{% endif %}\r\n\t\t</li>\r\n\t{% endfor %}\r\n</ul>\r\n```\r\n\r\n#### Considerations\r\nI set the new pagination up to use object attributes rather than an associative array, which seemed to make sense given that we are using a class.   To support the old `get_pagination` method I'm basically casting the object into an associative array using `get_object_vars`.  This approach seems to be passing tests fine, but let me know if you see any risks.\r\n\r\n#### Testing\r\nTests included!"},"comment":{"url":"https://api.github.com/repos/timber/timber/issues/comments/249400290","html_url":"https://github.com/timber/timber/pull/1173#issuecomment-249400290","issue_url":"https://api.github.com/repos/timber/timber/issues/1173","id":249400290,"user":{"login":"coveralls","id":2354108,"avatar_url":"https://avatars.githubusercontent.com/u/2354108?v=3","gravatar_id":"","url":"https://api.github.com/users/coveralls","html_url":"https://github.com/coveralls","followers_url":"https://api.github.com/users/coveralls/followers","following_url":"https://api.github.com/users/coveralls/following{/other_user}","gists_url":"https://api.github.com/users/coveralls/gists{/gist_id}","starred_url":"https://api.github.com/users/coveralls/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coveralls/subscriptions","organizations_url":"https://api.github.com/users/coveralls/orgs","repos_url":"https://api.github.com/users/coveralls/repos","events_url":"https://api.github.com/users/coveralls/events{/privacy}","received_events_url":"https://api.github.com/users/coveralls/received_events","type":"User","site_admin":false},"created_at":"2016-09-25T03:23:40Z","updated_at":"2016-09-25T03:23:40Z","body":"\n[![Coverage Status](https://coveralls.io/builds/8038128/badge)](https://coveralls.io/builds/8038128)\n\nCoverage decreased (-0.1%) to 90.167% when pulling **1b4d8efb371cf2cc9f032ca247394e3d2b01880a on 1118-pagination-api** into **dbed6b4bd6a4d5f954d85dd9a4a05e6c2da086ab on master**.\n"}}
{"actor":{"display_login":"coveralls"}}