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.

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/
share|improve this question

2 Answers 2

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
1  
@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

 
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.