• i am having a problem with my code:
    My conditional statement works for all cases except arts-entertainment page. When testing the code i determined that it is the is_page(‘arts-entertainment’) that is not working… When replacing the argument with any page name ie. ‘business’ the code works fine….consider me stumped!!?

    Below is my code, any help would be appreciated.

    ===================

    <?php
    if ( in_category(‘news’) || post_is_in_descendant_category( 13 ) ) {
    include ‘includes/nav-home.php’;
    }
    elseif ( in_category(‘business’) || post_is_in_descendant_category( 14 ) || is_page(‘business’)) {
    include ‘includes/nav-bus.php’;
    }
    elseif ( in_category(‘arts-entertainment’) || post_is_in_descendant_category( 17 ) || is_page(‘arts-entertainment’)) {
    include ‘includes/nav-ent.php’;
    }
    elseif ( in_category(‘living’) || post_is_in_descendant_category( 19 ) || is_page(‘living’)) {
    include ‘includes/nav-liv.php’;
    }
    elseif ( in_category(‘opinion’) || post_is_in_descendant_category( 18 ) || is_page(‘opinion’)) {
    include ‘includes/nav-opn.php’;
    }
    elseif ( in_category(‘sports’) || post_is_in_descendant_category( 20 ) || is_page(‘sports’)) {
    include ‘includes/nav-spt.php’;
    }
    else {
    include ‘includes/nav-home.php’;
    }
    ?>

    ==================
    FYI: The idea is to use a different color for navigation for each page in the conditional statement.

    Any help would greatly appreciated!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter cblock

    (@cblock)

    No replies yet huh?
    Well im not one to stop trying….oddly enough after further investigations i found that the following code produced the results i wanted, but im sure that this is a sloppy hack.

    Any one know why this works…from my limited understanding, it would seem to me that WP is not recognizing the || is_page (‘arts-entertainment’) to be false. as stated before changing the is_page() argument…results true. I tried using the page ID (577) as the argument for is_page(), but still returns false. After further testing, i deduced that “somehow?!?” WP thinks that the Arts & Entertainment page is a child of the ‘news’ category (13)…thus the following sloppy hack

    if ( in_category(‘news’) || post_is_in_descendant_category( 13 )) {
    if ( is_page(577)){
    include ‘includes/nav-ent.php’;
    }
    else
    include ‘includes/nav-home.php’;
    }

    was used to replace the first condition in the code from the prev post.

    You know how coding is sometimes….”just make it work”, even when we know its just a quick fix, hard code hack…just looking for any clarity on this issue.

    …WP is not recognizing the || is_page (‘arts-entertainment’) to be false…

    This implies that one or both of your other conditionals is true, thereby making the whole elsif true. But… I don’t get it. Don’t you want that elseif to be true so that it includes nav-ent.php?

    Thread Starter cblock

    (@cblock)

    @ apljdi;

    correction

    …WP is not recognizing the || is_page (‘arts-entertainment’) to be true

    Yes, you have the right idea, but the arts-entertainment condition returns true for all cases except for the || is_page (‘arts-entertainment’) – that’s where i test to see if the current page is the “Arts & Entertainment” page; in such a case include the nav-ent.php else continue

    try using wp_reset_query(); in front of the whole process.. TheLoop does strange things when called twice without being reset

    (Worked for me..)

    kjeft

    (@kjeft)

    This very same problem have been driving me mad for days, thanks Llasse!

    hbrizuela

    (@hbrizuela)

    try this

    if ($post->post_type==’page’)
    {
    //Your code here below
    }

    hbrizuela

    (@hbrizuela)

    sorry there was a thing missing in my previous, this below should work

    if (($post->post_type==’page’) && ($post->post_title==’pageName’))
    {
    //your code here
    }

    Had a similar problem… none of my is_page() detection functions were working, until I added this to the top of my sidebar.php file.

    wp_reset_query();

    Thanks Llasse!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘is_page not “completely” working’ is closed to new replies.