Support » Fixing WordPress » php conditional statement problem, wordpress issue?

  • I have a real issue right now with a conditional statement that I’m trying to get working. Maybe someone out there has solved it somehow or knows more php than I do.

    Here is the link to the php code I’m using:

    What the above code does is pull the latest three posts from a specified catagory into the sidebar. That’s great, but I want to go a step further. I want to have the code only execute on a specific page, and not others.

    I’ve tried using the ‘is_page’ conditional statement, but I can’t seem to code it right. I’ve put it after the ‘in_catagory’ using && and no dice. Also tried a double if statement…with no success. I don’t even get an error. It just doesn’t work.

    Is is possible to do or am I just spinning gears?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello

    If I understand you only want this code to execute on a specific page? If this is correct you just need to surround it with an ( if is_page(id) ) like below.

    <?php if ( is_page(page id number or name) ) { ?>
    <h2>Journal</h2><ul><?php query_posts('cat=4&showposts=3'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php if ( in_category(4) ) { ?>
    <li><a href=<?php the_permalink(); ?>><?php the_title(); ?></a></li>
    <?php } else {
    }; ?>
    <?php endwhile; ?>
    <?php } ?>

    If I have misunderstood or you have more questions just ask. 🙂

    You sir, are a god among men…thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘php conditional statement problem, wordpress issue?’ is closed to new replies.