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:


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

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

The same, with built-in function:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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