From b8d7682921b4125ab99808827b51c5d70a1ed8d7 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 11 Jul 2009 15:39:05 -0400 Subject: [PATCH] more cleanup of index.php and nav things --- addons/Core/Core.inc | 14 ++- addons/Core/partials/options-admin.inc | 6 ++ classes/ComicPress.inc | 68 ++++++++++--- functions.php | 2 + index.php | 136 +++++++++++++------------ 5 files changed, 147 insertions(+), 79 deletions(-) diff --git a/addons/Core/Core.inc b/addons/Core/Core.inc index 49a8f8c..07cf40e 100644 --- a/addons/Core/Core.inc +++ b/addons/Core/Core.inc @@ -1,11 +1,10 @@ comicpress = $comicpress; } @@ -18,6 +17,14 @@ class ComicPressAddonCore extends ComicPressAddon { } } + function show_comic($override_post) { + global $post; + $post_to_use = (is_null($override_post)) ? $this->comicpress->get_last_comic() : $post; + + $comic_post = new ComicPressComicPost($post_to_use, &$this); + $comic_post->display_comics(); + } + function setup_comic_metadata_buttons($form_fields, $post) { $comic_image_types = array( 'none' => __('Not a comic', 'comicpress'), @@ -159,6 +166,9 @@ class ComicPressAddonCore extends ComicPressAddon { } } break; + case 'blogpost_count': + $this->comicpress->comicpress_options[$option] = (int)$_POST['cp'][$option]; + break; } } } diff --git a/addons/Core/partials/options-admin.inc b/addons/Core/partials/options-admin.inc index c1deea8..d94ebcd 100644 --- a/addons/Core/partials/options-admin.inc +++ b/addons/Core/partials/options-admin.inc @@ -23,6 +23,12 @@ + + + + + +   diff --git a/classes/ComicPress.inc b/classes/ComicPress.inc index 6c4d21e..2924122 100644 --- a/classes/ComicPress.inc +++ b/classes/ComicPress.inc @@ -6,7 +6,8 @@ class ComicPress { 'comic_dimensions' => '760x', 'rss_dimensions' => '350x', 'archive_dimensions' => '125x', - 'category_order' => false + 'category_order' => false, + 'blogpost_count' => 10 ); var $comic_post_attachments_cache = array(); @@ -16,7 +17,7 @@ class ComicPress { function load() { $result = get_option('comicpress-options'); if (is_array($result)) { - $this->comicpress_options = $result; + $this->comicpress_options = array_merge($this->comicpress_options, $result); } } @@ -33,7 +34,7 @@ class ComicPress { $this->separate_categories(); $this->sort_comic_categories(); } - + /** * Flatten all WP categories into nodes like 0/3/5. */ @@ -157,7 +158,7 @@ class ComicPress { function get_terminal_post_in_category($category_id, $first = true) { $sort_order = $first ? "asc" : "desc"; $terminal_comic_query =$this->_new_wp_query(); - $terminal_comic_query->query("showposts=1&order=${sort_order}&cat=${category_id}"); + $terminal_comic_query->query("showposts=1&order=${sort_order}&cat=${category_id}&status=publish"); if ($terminal_comic_query->have_posts()) { return reset($terminal_comic_query->posts); } @@ -165,20 +166,50 @@ class ComicPress { } function get_first_comic() { - return $this->get_terminal_post_in_category($this->get_all_comic_categories_as_cat_string); + return $this->get_terminal_post_in_category($this->get_all_comic_categories_as_cat_string()); } function get_last_comic() { - return $this->get_terminal_post_in_category($this->get_all_comic_categories_as_cat_string, false); + return $this->get_terminal_post_in_category($this->get_all_comic_categories_as_cat_string(), false); } - function get_adjacent_comic($category, $next = false) { - $categories_to_exclude = $this->non_comic_categories; + function get_nav_comics() { + $comic_posts = array(); + foreach (array('first', 'last', 'previous', 'next') as $which) { + $comic_posts[$which] = $this->{"get_${which}_comic"}(); + } + + $comic_posts['show_first'] = ($comic_posts['first']->ID !== $comic_posts['last']->ID); + $comic_posts['show_previous'] = (!empty($comic_posts['previous']) && ($comic_posts['first']->ID !== $comic_posts['previous']->ID)); + $comic_posts['show_next'] = (!empty($comic_posts['next']) && ($comic_posts['last']->ID !== $comic_posts['next']->ID)); + + return $comic_posts; + } + + function get_adjacent_comic($category, $next = false, $override_post = null) { + global $wp_query, $post; + $temp = $wp_query->is_single; + $wp_query->is_single = true; + + if (!is_null($override_post)) { + $temp_post = $post; + $post = $override_post; + } + + $categories_to_exclude = $this->get_leaves_of_tree($this->non_comic_categories); if (!is_null($category)) { - $categories_to_exclude = $this->get_string_to_exclude_all_but_provided_categories($category); + $categories_to_exclude = $this->exclude_all_but_provided_categories($category); + } + + $result = get_adjacent_post(false, implode(" and ", $categories_to_exclude), !$next); + + $wp_query->is_single = $temp; + + if (!is_null($override_post)) { + $post = $temp_post; } - return get_adjacent_post(false, $categories_to_exclude, $next); + return empty($result) ? false : $result; } /** @@ -186,10 +217,19 @@ class ComicPress { * filter out every category but the provided ones. */ function get_string_to_exclude_all_but_provided_categories($category) { - $category_ids = array_keys($this->get_all_category_objects_by_id()); - if (!is_array($category)) { $category = array($category); } return implode(",", array_diff($category_ids, $category)); } + + function exclude_all_but_provided_categories($category) { + $category_ids = array_keys($this->get_all_category_objects_by_id()); + if (!is_array($category)) { $category = array($category); } + } + + function get_leaves_of_tree($tree) { + $leaves = array(); + foreach ($tree as $branch) { $leaves[] = end(explode("/", $branch)); } + return $leaves; + } function _new_wp_query() { return new WP_Query(); @@ -198,12 +238,12 @@ class ComicPress { /** * Get the previous comic from the current one. */ - function get_previous_comic($category = null) { return get_adjacent_comic($category); } + function get_previous_comic($category = null, $override_post = null) { return $this->get_adjacent_comic($category, false, $override_post); } /** * Get the next comic from the current one. */ - function get_next_comic($category = null) { return get_adjacent_comic($category, true); } + function get_next_comic($category = null, $override_post = null) { return $this->get_adjacent_comic($category, true, $override_post); } } ?> \ No newline at end of file diff --git a/functions.php b/functions.php index 37a6fd0..8f02af9 100644 --- a/functions.php +++ b/functions.php @@ -1,5 +1,7 @@ + - - in_the_loop = true; $comicFrontpage = new WP_Query(); $comicFrontpage->query('showposts=1&cat='.$comicpress->get_all_comic_categories_as_cat_string()); - while ($comicFrontpage->have_posts()) { - $comicFrontpage->the_post(); - - $comic_post = new ComicPressComicPost(&$post, &$comicpress); - - ?> - -
-
- display_comics() ?> -
-
- - -
- - have_posts()) : $comicFrontpage->the_post() ?> -
-
- -
- -
-
- -
  • ', multiple) ?>
- -

- -

-
- -
- -
- -
- -
-
-
- - -
- - - -
+ get_header(); +?> + +
+
+
- query('showposts='.$blog_postcount.'&cat=-'.$comiccat.'&paged='.$paged); - while ($wp_query->have_posts()) : $wp_query->the_post() ?> +
+ +get_nav_comics(); + + $post = $nav_comics['last']; ?> +
+
+ +
+ +
+
+ +
  • ', multiple) ?>
+ +

+ post_title ?> +

+
+ +
+ +
+ +
+ +
+
+
+ + +
+ +query( + 'showposts=' . + (int)$comicpress->comicpress_options['blogpost_count'] . + '&cat=-' . + $comicpress->comicpress_options['comic_category_id'] . + '&paged=' . + $paged + ); + + while ($wp_query->have_posts()) { + $wp_query->the_post() ?>

@@ -81,16 +92,15 @@

- + + - -
- + \ No newline at end of file