add current storyline helper method
This commit is contained in:
parent
705a38595a
commit
4f40c2457c
@ -30,6 +30,8 @@ class ComicPressDBInterface {
|
|||||||
* Find the terminal post in a specific category.
|
* Find the terminal post in a specific category.
|
||||||
*/
|
*/
|
||||||
function get_terminal_post_in_category($category_id, $first = true) {
|
function get_terminal_post_in_category($category_id, $first = true) {
|
||||||
|
global $wp_query;
|
||||||
|
|
||||||
$temp = $wp_query; $wp_query = null;
|
$temp = $wp_query; $wp_query = null;
|
||||||
$sort_order = $first ? "asc" : "desc";
|
$sort_order = $first ? "asc" : "desc";
|
||||||
$terminal_comic_query = new WP_Query();
|
$terminal_comic_query = new WP_Query();
|
||||||
|
@ -34,9 +34,17 @@ class ComicPressNavigation {
|
|||||||
if (is_array($valid = $this->_storyline->valid($category))) {
|
if (is_array($valid = $this->_storyline->valid($category))) {
|
||||||
foreach ($valid as $field) {
|
foreach ($valid as $field) {
|
||||||
$nav["storyline-chapter-${field}"] = $this->_dbi->get_first_comic($this->_storyline->{$field}($category));
|
$nav["storyline-chapter-${field}"] = $this->_dbi->get_first_comic($this->_storyline->{$field}($category));
|
||||||
|
|
||||||
|
if ($field == "previous") {
|
||||||
|
if ($post->ID != $nav['storyline-chapter-current']) {
|
||||||
|
$nav['storyline-chapter-previous'] = $nav['storyline-chapter-current'];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $nav;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@ class ComicPressStoryline {
|
|||||||
|
|
||||||
$adjacents_by_parent = array();
|
$adjacents_by_parent = array();
|
||||||
|
|
||||||
if (is_string($structure)) {
|
if (is_string($structure)) {
|
||||||
$structure = explode(',', $structure);
|
$structure = explode(',', $structure);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($structure)) {
|
if (is_array($structure)) {
|
||||||
$is_valid = true;
|
$is_valid = true;
|
||||||
@ -83,12 +83,13 @@ class ComicPressStoryline {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function current($id) { return $id; }
|
||||||
function parent($id) { return $this->_get_field('parent', $id); }
|
function parent($id) { return $this->_get_field('parent', $id); }
|
||||||
function previous($id) { return $this->_get_field('previous', $id); }
|
function previous($id) { return $this->_get_field('previous', $id); }
|
||||||
function next($id) { return $this->_get_field('next', $id); }
|
function next($id) { return $this->_get_field('next', $id); }
|
||||||
function valid($id) {
|
function valid($id) {
|
||||||
if (isset($this->_structure[$id])) {
|
if (isset($this->_structure[$id])) {
|
||||||
return array_keys($this->_structure[$id]);
|
return array_merge(array_keys($this->_structure[$id]), array('current'));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
|
|||||||
array('parent', 2, 1),
|
array('parent', 2, 1),
|
||||||
array('next', 2, 3),
|
array('next', 2, 3),
|
||||||
array('next', 3, 4),
|
array('next', 3, 4),
|
||||||
array('valid', 1, array('next')),
|
array('valid', 1, array('next', 'current')),
|
||||||
array('valid', 6, false),
|
array('valid', 6, false),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -117,11 +117,11 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
function providerTestGetValidNav() {
|
function providerTestGetValidNav() {
|
||||||
return array(
|
return array(
|
||||||
array(array(1), array('next')),
|
array(array(1), array('next', 'current')),
|
||||||
array(array(1,2), false),
|
array(array(1,2), false),
|
||||||
array(array(1,4), array('next')),
|
array(array(1,4), array('next', 'current')),
|
||||||
array(array(2), array('previous', 'next')),
|
array(array(2), array('previous', 'next', 'current')),
|
||||||
array(array(3), array('previous')),
|
array(array(3), array('previous', 'current')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user