0

Is it possible to get paged outside of the standard WP loop?

I already use this inside the loop:

<?php if ( $paged >= 2 ) { ?>  Some text for the 2nd page on up  <?php } ?>

But I'd like to be able to echo some text outside the loop on all pages two and greater. Possible? Or a better way?

0

2 Answers 2

4

Here you go:

<?php
if ( is_paged() )
  echo 'some text';

See http://codex.wordpress.org/Conditional_Tags#A_Paged_Page

5
  • This works fine inside the loop; I need something that works outside of the loop. Feb 27, 2011 at 22:23
  • 1
    It should work outside The Loop as well, unless you're using query_posts() wrong.
    – scribu
    Feb 27, 2011 at 22:30
  • I'm using the standard WP loop. Feb 27, 2011 at 22:35
  • 1
    So, you're saying that it works inside while ( have_posts() ) ... but not before it? Try deactivating all plugins; then try switching to the default theme.
    – scribu
    Feb 27, 2011 at 23:11
  • Argg.... Had another php conditonal for paged higher up in the code that was conflicting. Thanks. Mar 1, 2011 at 17:42
-2

You can make a "second" Loop like this:

<?php $posts = query_posts($query_string); if (have_posts()) : while (have_posts()) : the_post();
  if ($paged >= 2) {echo "your content";}
endwhile; endif; ?>

Now you can use the $paged where ever you want.

Like in the comments quoted this was not the best solution. It was really quick and dirty.

After a little test: You can use $paged outside the loop. But you can query the active page where you want in the code with

<?php get_query_var('paged'); ?>

Because the active page is a parameter of the active URL. For your question:

if (get_query_var('paged') >=2) {
  echo "text for pages from 2 and up";
} else {
  echo "text for the first page";
}
3
  • 1
    That's wasteful.
    – scribu
    Feb 27, 2011 at 21:33
  • You are right it is a quick and dirty solution. But it is a solution at all. I think a good way is to output the text in the loop, like in a DIV-Element and place it with CSS.
    – Guru 2.0
    Feb 27, 2011 at 21:38
  • Can't get this to work with the standard WP loop.... Feb 27, 2011 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.