0

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:

example.com/taiwantalk/forums/topic/technology-topic-11/

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

example.com/taiwantalk/forums/topic/technology-topic-11/page/2/
1

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

if ( ! isset ( $GLOBALS['paged'] ) or ( $GLOBALS['paged'] < 2 ) )
{
    // run your code
}
  • 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
3

The same, with built-in function:

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

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.