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

For example, I want to query posts in a page. But I don't want to show them when the user clicks the pagination links.

Pretty much like what happens in Youtube. You only see the Top comments in the first page but when you click Next they disappear.

Any suggestions to accomplish this?

URL example:

Query the posts if it is the first page:


Don't query them if it is the second page or any other:

share|improve this question
up vote 1 down vote accepted

The current page number is available in a global variable $paged.

if ( ! isset ( $GLOBALS['paged'] ) or ( $GLOBALS['paged'] < 2 ) )
    // run your code
share|improve this answer
why not just $paged? – Ashfame Mar 26 '11 at 7:38
it worked perfectly thanks! – janoChen Mar 26 '11 at 7:45
@Ashfame That will not work if register_globals are off and the loop happens not in the global context. – toscho Mar 26 '11 at 7:45

The same, with built-in function:

<?php if ( ! get_query_var('paged')) : ?>
    { your code here }
<?php endif; ?>
share|improve this answer

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.