handle previous posts w/ pages

This commit is contained in:
John Bintz 2009-11-28 14:56:43 -05:00
parent 11045bc588
commit b0a829ecb6
2 changed files with 20 additions and 4 deletions

View File

@ -143,16 +143,22 @@ class GraphicalNavigationWidgetTest extends PHPUnit_Framework_TestCase {
),
array(
array('enable_multipage_support' => 'on'),
array('previous' => 'prev-post', 'next' => 'next-post'),
array('previous' => (object)array('post_content' => 'test', 'guid' => 'prev-post', 'post_status' => 'publish'), 'next' => 'next-post'),
1, 1,
array('previous' => 'prev-post', 'next' => 'next-post')
array('previous' => (object)array('post_content' => 'test', 'guid' => 'prev-post', 'post_status' => 'publish'), 'next' => 'next-post')
),
array(
array('enable_multipage_support' => 'on'),
array('previous' => 'prev-post', 'next' => 'next-post'),
array('previous' => (object)array('post_content' => 'test<!--nextpage-->test2', 'guid' => 'prev-post', 'post_status' => 'publish'), 'next' => 'next-post'),
1, 1,
array('previous' => 'prev-post/2/', 'next' => 'next-post')
),
array(
array('enable_multipage_support' => 'on'),
array('previous' => (object)array('post_content' => 'test', 'guid' => 'prev-post', 'post_status' => 'publish'), 'next' => 'next-post'),
1, 2,
array(
'previous' => 'prev-post',
'previous' => (object)array('post_content' => 'test', 'guid' => 'prev-post', 'post_status' => 'publish'),
'next' => 'current-post/2/',
'storyline-next' => 'current-post/2/',
)

View File

@ -344,6 +344,16 @@ class GraphicalNavigationWidget extends WP_Widget {
if ($page != 1 && $numpages > 1) {
$post_nav['previous'] = $post_nav['storyline-previous'] = $this->_build_in_post_page_link($post, $page - 1);
}
if ($page == 1) {
foreach (array('previous', 'previous_storyline') as $which) {
if (isset($post_nav[$which])) {
$count = preg_match_all('#<!--nextpage-->#', $post_nav[$which]->post_content, $matches);
if (!empty($count)) {
$post_nav[$which] = $this->_build_in_post_page_link($post_nav[$which], $count + 1);
}
}
}
}
}
return array($post_nav, $post, $instance);