• Resolved trishahdee

    (@trishahdee)


    I need to write a conditional statement that says: if not these pages AND is not the blog then…

    NOTE: The blog is not the front page but is set as it’s own static page in Settings > Reading.

    The following works for the ‘not pages’ part:

    <?php if( !is_page(array(8211,4177,5019,11)) ) : ?> information here <?php endif; ?>

    But when I try to add the ‘not blog’ part it doesn’t work. I’ve tried the following:
    <?php if( !is_page(array(8211,4177,5019,11,'blog')))) : ?>
    <?php if( !is_page(array(8211,4177,5019,11)) && !is_blog ()) : ?>
    <?php if( !is_page(array(8211,4177,5019,11)) && !is_blog_installed ()) : ?>

    What am I doing wrong?

    Your help is greatly appreciated!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Pioneer Web Design

    (@swansonphotos)

    Can you make your blog a page of posts and go from there?

    Thread Starter trishahdee

    (@trishahdee)

    I’m not sure what you are asking me to try. Can you explain in more detail what you are suggesting?

    Pioneer Web Design

    (@swansonphotos)

    Michael

    (@alchymyth)

    if with ‘blog’ you mean the ‘posts page’, then to check for the ‘posts page’ you can use https://codex.www.ads-software.com/Function_Reference/is_home

    example:

    <?php if( !is_page(array(8211,4177,5019,11)) && !is_home() ) : ?>

    Thread Starter trishahdee

    (@trishahdee)

    Thank you for your help.

    @alchymyth I have a custom homepage and the blog is on another page so your solution doesn’t work.

    @pioneer I already created a separate page for the blog. But I did take it one step further and created a custom template for the blog and assigned it to the blog page, but this still did nothing.

    I did however find a solution!

    NOTE: I’m using the “WP Directory” theme by AIT Themes (https://www.ait-themes.com/wordpress-themes/directory-wordpress-theme/) which uses the WpLatte template system.

    The blog page has always had the class .blog in the body tag, so I used that to identify the page. Here is what I did:

    Just before closing head </head> I added this which grabs whatever classes are assigned to the page:

    <?php
    $classes = get_body_class();
    ?>
    </head>

    Then (even though I’m trying to add an ID to the body which should go BEFORE the classes) I added the following AFTER the <body> classes:

    id="<?php if( !is_page(array(211,4177,5019,11)) && !in_array('blog',$classes)) : ?> my_code_here <?php endif; ?>"

    And it works! The first part makes sure it’s not on the page IDs in the array, and the second part checks to see if “blog” is one of the classes assigned to the body, if it is not on any of these pages then the “my_code_here” is applied and creates an ID using the category name.

    The body tag looks like this:

    <body <?php body_class('ait-directory'); ?> id="<?php if( !is_page(array(211,4177,5019,11)) && !in_array('blog',$classes)) : ?> my_code_here <?php endif; ?>" >

    I hope this helps someone else.

    Thread Starter trishahdee

    (@trishahdee)

    Marking as resolved.

    Michael

    (@alchymyth)

    I have a custom homepage and the blog is on another page so your solution doesn’t work.

    have you actually tried it?
    I am still confident, that using is_home() should have worked for the ‘blog’ page, if those pages are set from within ‘settings – reading – front page displays’.

    review https://codex.www.ads-software.com/Function_Reference/is_home

    Thread Starter trishahdee

    (@trishahdee)

    UGH. You are right @alchymyth!

    I just assumed that is_home only worked for the homepage, but as it says on your reference page “On the blog posts index, is_home() will always return TRUE, regardless of whether the blog posts index is displayed on the site front page or a separate page.”

    That will teach me to assume! (*^_^*)

    Thank you very much ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Conditional if not multiple page and if not blog’ is closed to new replies.