Forums

is_page not working (7 posts)

  1. drugoholic
    Member
    Posted 7 months ago #

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                <?php if (!is_page('57') &amp;&amp; !is_page('61') &amp;&amp; !is_page('59')){ ?>
    			<div style="text-align: left;"><h1><?php the_title(); ?></h1></div><br />
                <?php } else { ?>
               <div style="text-align: right;"><h1><?php the_title(); ?></h1></div><br />
                     <? } ?>

    Shouldn't this work? is there anything wrong with the code?
    Whenever I goto page id(61) the title is being displayed on the right instead of the left. :\

  2. Mankot
    Member
    Posted 7 months ago #

    Are you using a custom query or several loops on one page? Try to insert
    <?php wp_reset_query(); ?>
    just above the loop

  3. stvwlf
    Member
    Posted 7 months ago #

    That depends on the context in which that code is being used - if WP is not seeing that content display as a page, then it will skip the first condition and display the 2nd.

    A good debugging plugin is
    http://wordpress.org/extend/plugins/askapache-what-is-this/
    which will display if WP is seeing a Page, a Category, a Single post, etc. Many times issues like this are because WP is not interpreting the request the way you think it is. At times even if it seems to be page 57, WP is not testing for page #'s.

    Also, as a general practice its best to phrase logic without NOTS...

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                <?php if (is_page('57') || is_page('61') || is_page('59')){ ?>
    			<div style="text-align: right;"><h1><?php the_title(); ?></h1></div><br />
                <?php } else { ?>
               <div style="text-align: left;"><h1><?php the_title(); ?></h1></div><br />
                     <? } ?>
  4. Mankot
    Member
    Posted 7 months ago #

    Btw make sure that this is really an conditional tag issue and not just a problem with your css by inserting some echo.
    E.g. put
    <?php echo "left"; ?>
    in the if-clause and
    <?php echo "right" ?>
    in the else clause

  5. haryadimas
    Member
    Posted 6 months ago #

    @Mankot

    thanks a lot. i've been looking for the answer to my problem for ages.
    turns out that the loop for recent news on my sidebar makes wordpress thinks that the current displayed page was not a page at all.

    this code:
    <?php wp_reset_query(); ?>

    solves my problem.

    thank you..

  6. cblock
    Member
    Posted 2 months ago #

    i am having a similar problem:
    My conditional statement works for all cases except arts-entertainment page. 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.

  7. TonyGeer
    Member
    Posted 2 months ago #

    mankot, thanks a lot! That worked. I had the exact problem that haryadimas had - I inserted some code to show the title of the most recent posts above it and it stopped working.

    Thanks again!

Reply

You must log in to post.

About this Topic

Tags