[wp-hackers] how to check if current loop is main loop?
Konrad Karpieszuk
kkarpieszuk at gmail.com
Sun May 29 16:57:42 UTC 2011
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
More information about the wp-hackers
mailing list