Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers 2

up vote 4 down vote accepted

Here you go:

<?php
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. –  songdogtech Feb 27 '11 at 22:23
1  
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. –  songdogtech Feb 27 '11 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 '11 at 23:11
    
Argg.... Had another php conditonal for paged higher up in the code that was conflicting. Thanks. –  songdogtech Mar 1 '11 at 17:42
add comment

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
1  
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.... –  songdogtech Feb 27 '11 at 22:36
add comment

Your Answer

 
discard

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.