• Can anyone tell me why this does not work:

    <?php if (in_category(‘4’)): ?>
    <?php if (is_page(2164)): ?>
    <h1 class=”post-title”><?php the_title(); ?></h1>
    <?php endif; ?>
    <?php else: ?>
    <h1 class=”post-title”><?php the_title(); ?></h1>
    <?php endif; ?>

    Page 2164 is a Post within my projects section and it has a different layout than all other project pages.

Viewing 2 replies - 1 through 2 (of 2 total)
  • the ‘is_page()’ is within a ‘in_category()’ conditional statement, and is therefore never checked (pages do not have categories).

    what are you trying to check with your conditional statements?

    are you possibly trying to work with ‘elseif’?

    http://php.net/manual/en/control-structures.elseif.php

    Page 2164 is a Post

    this is a contradiction – either page or post
    did you try to check for is_single() ?
    https://codex.ww.wp.xz.cn/Function_Reference/is_single

    Thread Starter esilk

    (@esilk)

    @michael – is_single(2164) almost seems to work. Here’s what I’m trying to accomplish:

    <?php if (in_category('4')): ?>
    <?php elseif (is_single(2164)): ?>
                    <h1 class="post-title"><?php the_title(); ?></h1>
    <?php else: ?>
                    <h1 class="post-title"><?php the_title(); ?></h1>
    <?php endif; ?>
    <?php if (!is_single(2164)): ?>
                    <div id="detailslink"><a id="down1" class="down link" href="#details"><img src="/wp-content/themes/rally/images/details.gif" width="139" height="35" alt="More Details" /></a></div>
    <?php endif; ?>

    So on post 2164, the detailslink div does NOT show up, and it does appear on all other posts. However, the title does NOT display as it should.

    I can force the title this way, but I thought there should be something a little more elegant:

    <?php $postid = get_the_ID(); ?>
    <?php if ($postid == 2164): ?>
                    <h1 class="post-title"><?php the_title(); ?></h1>
    <?php endif; ?>
    <?php if (in_category('4')): ?>
    <?php elseif (is_single(2164)): ?>
                    <h1 class="post-title"><?php the_title(); ?></h1>
    <?php else: ?>
                    <h1 class="post-title"><?php the_title(); ?></h1>
    <?php endif; ?>
    <?php if ($postid != 2164): ?>
                    <div id="detailslink"><a id="down1" class="down link" href="#details"><img src="/wp-content/themes/rally/images/details.gif" width="139" height="35" alt="More Details" /></a></div>
    <?php endif; ?>
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Conditional is_page not working’ is closed to new replies.