0

I want to determine when it's the following page:

  1. Front page displays the Blog page
  2. Front page displays the Blog page + subpages: /page/2/...
  3. Front page as static page
  4. Blog page as static page
  5. Blog page as static page + subpages: /page/2/...

The number 1 and the number 3 are easy thanks to the tag is_front_page(). And at the moment, the following code works for me in the 5 points:

switch ( true ) {
    case ( is_home() && 'page' && ! is_front_page() && get_query_var( 'paged' ) > 1 ) :
        // Number 5
        break;

    case ( is_home() && 'page' && ! is_front_page() ) :
        // Number 4
        break;

    case ( 'posts' == get_option( 'show_on_front' ) && get_query_var( 'paged' ) > 1 ) :
        // Number 2
        break;

    case ( is_front_page() ) :
        // Number 1 and 3
        break;
}

The problem comes that this code is having a conflict with the category archive. The category archive has the same result of the numbers 2 and 5. So I don't know what I'm doing wrong here.

  • I don't see that issue. I think there may be some information missing-- perhaps something in the theme code. – s_ha_dum Nov 13 '15 at 2:25
  • @s_ha_dum It was really strange, to be honest. I'm developing a theme and I have this into a function separated from the others. I posted an answer below that fixes my problem. Still I'm not sure if it's perfect, but it works (I checked most of the pages and archives). – Gerard Nov 13 '15 at 2:41
0

Ok, I solved the question, after all. The comments are into the code:

global $paged;
switch ( true ) {

    // Determine if the blog is a static page (subpages)
    case ( is_home() && 'page' && ! is_front_page() && $paged > 1 ) :
        break;

    // Determine if the blog is a static page (first page)
    case ( is_home() && 'page' && ! is_front_page() ) :
        break;

    // Determine if it's the front page and displays the blog (subpages) 
    case ( is_home() && 'posts' && $paged > 1 ) :
        break;

    // Determine if it's the front page: blog and static (both)
    case ( is_front_page() ) :
        break;
}

That's very useful, for example, if we want to display the blog page in the front page and, at the same time, we want to disable the indexation of the subpages because we already have the categories archives (to avoid duplicate content).

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.