[wp-hackers] how to check if current loop is main loop?

Konrad Karpieszuk kkarpieszuk at gmail.com
Sun May 29 17:11:27 UTC 2011


ok, looks that i found solution :)

/* Plugin Name: Loop test */
function wyswietl_slider($array) {
 global $wp_the_query, $wp_query, $post, $wp;
 if ($array === $wp_query) :
 echo "it is main loop";
 endif;
}
add_action('loop_start', 'wyswietl_slider');

the diffrence is that i passed $array to function and i checked if
$array === $wp_query



On Sun, May 29, 2011 at 6:57 PM, Konrad Karpieszuk
<kkarpieszuk at gmail.com> wrote:
> On Sat, May 28, 2011 at 11:50 PM, Andrew Nacin <wp at andrewnacin.com> wrote:
>> To check if you're on the main loop: $wp_the_query === $wp_query
>
>
> i wrote my opinion little too fast :) it isnt working (or i dont
> understand smth, or i didnt explain what i need well).
>
> short plugin:
>
> /* Plugin Name: Loop test */
> function wyswietl_slider() {
>  global $wp_the_query, $wp_query, $post, $wp;
>  if ($wp_the_query === $wp_query) :
>  echo "it is main loop";
>  endif;
> }
> add_action('loop_start', 'wyswietl_slider');
>
> it shows text "it is main loop" above main loop. but it shows also
> above other loops.
>
> for example in sidebar i have standard widget to to show "Last posts".
> over last posts i see also text "it is main loop". Even in situation
> when WP displays single post (and in sidebar i have few last posts, so
> main loop and loop in widget isnt thesame)
>
> Andrew (and others), what i did wrong? :)
>
>
>
> --
> (en) regards / (pl) pozdrawiam
> Konrad Karpieszuk
>



-- 
(en) regards / (pl) pozdrawiam
Konrad Karpieszuk


More information about the wp-hackers mailing list