1

So my issue is that I need to create two versions of a category.php template. Now, I know very well that if I want to display posts from just one category, I duplicate category.php and call it category-xx.php for the slug or ID number. Great. Got that.

The problem is the client wants it where on the first page of posts, only 4 posts appear. 6 on all subsequent pages. Worse, she wants a div with additional content to appear above the posts but only on the first page. So http://www.yoursite.com/category/whatever/page/2/ and /page/3/ look different than http://www.yoursite.com/category/whatever/.

Now I know I could use conditional comments like is_page() to specify a certain page to display let's say, a certain div. But how would I do it in this sense? Can I do it? There must be some kind of if...else statement that'll make this work.

1
  • Hey, did you get any solution>? I am still looking for good solution to this problem i have with woo-commerce and elementor based custom page. I just want to show it on first page and not other pages. Commented Sep 8, 2021 at 6:38

1 Answer 1

2

get_query_var('paged') will show you pagination information. The code below will show only on first page of archive

if(get_query_var('paged') == 1){
    //run extra code    
}
2
  • Works in informational way, but getting non-consistent amount of posts per page correcty is waaay more convoluted. :(
    – Rarst
    Commented Jun 25, 2013 at 21:23
  • 1
    I actually had the same problem, but since WordPress shows the first page not as ../page/1 but simply as ../, and get_query_var returned 0 on this page, while 2,3,... on all the later pages, I at the end used if (get_query_var('paged') == 0){ /* do first page thing*/}
    – norbert
    Commented Oct 8, 2014 at 4:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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