diff --git a/test/widgets/GraphicalNavigationWidgetTest.php b/test/widgets/GraphicalNavigationWidgetTest.php index 53e35ab..5a856d5 100644 --- a/test/widgets/GraphicalNavigationWidgetTest.php +++ b/test/widgets/GraphicalNavigationWidgetTest.php @@ -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' => 'testtest2', '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/', ) diff --git a/widgets/GraphicalNavigationWidget.inc b/widgets/GraphicalNavigationWidget.inc index 3409b79..5343527 100644 --- a/widgets/GraphicalNavigationWidget.inc +++ b/widgets/GraphicalNavigationWidget.inc @@ -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('##', $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);