From 01e2073aeef3f852b6a23994986f77652a22e195 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 20 Dec 2009 09:46:38 -0500 Subject: [PATCH] add new storyline-based archive dropdown option --- widgets/ArchiveDropdownWidget.inc | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/widgets/ArchiveDropdownWidget.inc b/widgets/ArchiveDropdownWidget.inc index 13db24e..44d49d7 100644 --- a/widgets/ArchiveDropdownWidget.inc +++ b/widgets/ArchiveDropdownWidget.inc @@ -19,7 +19,8 @@ class ArchiveDropdownWidget extends WP_Widget { $this->modes = array( 'monthly_archive' => __('Monthly archive', 'comicpress'), 'comic_archive' => __('Comic archive', 'comicpress'), - 'storyline_order' => __('Storyline order', 'comicpress'), + 'storyline_order' => __('Storyline archive pages', 'comicpress'), + 'storyline_order_post_link' => __('Storyline posts', 'comicpress'), ); } @@ -130,6 +131,31 @@ class ArchiveDropdownWidget extends WP_Widget { return $this->build_dropdown($results); } + /** + * Build dropdown based on storyline order, linking to the first post in each category. + */ + function build_storyline_order_post_link_dropdown() { + $storyline = $this->_new_comicpressstoryline(); + $storyline->read_from_options(); + + $dbi = $this->_new_comicpressdbinterface(); + + $results = array(); + if (!empty($storyline->_structure)) { + foreach ($storyline->_structure as $id => $info) { + $category = get_category($id); + if (!empty($category)) { + $post = $dbi->get_first_post($id); + if (!empty($post)) { + $results[get_permalink($post)] = str_repeat(' ', ($info['level'] - 1) * 3) . $category->name; + } + } + } + } + + return $this->build_dropdown($results); + } + /** * Render the widget. */ @@ -202,4 +228,4 @@ class ArchiveDropdownWidget extends WP_Widget { } } -add_action('template_redirect', array('ArchiveDropdownWidget', 'template_redirect')); \ No newline at end of file +add_action('template_redirect', array('ArchiveDropdownWidget', 'template_redirect'));