WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 4 down vote accepted

Here you go:

if ( is_paged() )
  echo 'some text';

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

share|improve this answer
This works fine inside the loop; I need something that works outside of the loop. – markratledge Feb 27 '11 at 22:23
It should work outside The Loop as well, unless you're using query_posts() wrong. – scribu Feb 27 '11 at 22:30
I'm using the standard WP loop. – markratledge Feb 27 '11 at 22:35
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 '11 at 23:11
Argg.... Had another php conditonal for paged higher up in the code that was conflicting. Thanks. – markratledge Mar 1 '11 at 17:42

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";
share|improve this answer
That's wasteful. – scribu Feb 27 '11 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 '11 at 21:38
Can't get this to work with the standard WP loop.... – markratledge Feb 27 '11 at 22:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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