2

I want certain widgets to not appear on page 1 of a paginated post, but appear on all other pages (page 2, 3 .. so on), and some other widgets to appear on only appear on page 1 and not the rest of the paginated pages.

I installed a plugin that lets you execute php in widgets, and then tried the following conditions in my widget:

  1. This didn't work:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    if(1 != $paged)
    
  2. This didn't work either:

    if(!is_paged())
    
  3. This didn't too:

    if($page>1)
    

I then installed the plugin "widget logic" and tried the condition is_paged() but that didn't work either.

That function is not global certainly.

Can anyone suggest how should I go about it?

  • The codex page for is_paged explains why it doesn't work in your case. page is the query var on paginated posts, paged is the query var on archive pages. – Milo Jan 19 '16 at 19:17
  • @Milo, I see, but I tried if(is_page()) condition and that didn't work either. – gxtj Jan 19 '16 at 19:39
  • the page query var was in reference to your first code snippet. is_page is for detecting the page post type. – Milo Jan 19 '16 at 19:40
  • @Milo Thanks! That worked like a charm. $paged = (get_query_var('page')) ? get_query_var('page') : 1; if(1 != $paged) Please make it an answer. – gxtj Jan 19 '16 at 21:50
3

As per the last comment, this is the correct answer:

$paged = get_query_var( 'page', 1 );
if(1 != $paged) ...

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.