From 7623634aaf1bb3031f8dda0ae7d02fd1652b0ecf Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Sun, 17 Jul 2005 16:58:13 +0000 Subject: [PATCH] in_the_loop() Props: Mark Jaquith fixes #1518 git-svn-id: https://develop.svn.wordpress.org/trunk@2716 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/classes.php | 7 +++++++ wp-includes/functions.php | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/wp-includes/classes.php b/wp-includes/classes.php index ca4c0821bc..94f3e526a0 100644 --- a/wp-includes/classes.php +++ b/wp-includes/classes.php @@ -9,6 +9,7 @@ class WP_Query { var $posts; var $post_count = 0; var $current_post = -1; + var $in_the_loop = false; var $post; var $is_single = false; @@ -55,6 +56,7 @@ class WP_Query { unset($this->queried_object_id); $this->post_count = 0; $this->current_post = -1; + $this->in_the_loop = false; } // Reparse the query vars. @@ -593,6 +595,7 @@ class WP_Query { function the_post() { global $post; + $this->in_the_loop = true; $post = $this->next_post(); setup_postdata($post); } @@ -600,8 +603,12 @@ class WP_Query { function have_posts() { if ($this->current_post + 1 < $this->post_count) { return true; + } elseif ($this->current_post + 1 == $this->post_count) { + // Do some cleaning up after the loop + $this->rewind_posts(); } + $this->in_the_loop = false; return false; } diff --git a/wp-includes/functions.php b/wp-includes/functions.php index e8e8ba3b24..8c095f2acb 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1413,6 +1413,12 @@ function is_paged () { return $wp_query->is_paged; } +function in_the_loop() { + global $wp_query; + + return $wp_query->in_the_loop; +} + function get_query_var($var) { global $wp_query;