WordPress.org

Ready to get started?Download WordPress

Forums

php conditional statement problem, wordpress issue? (3 posts)

  1. axiomjunglist
    Member
    Posted 7 years ago #

    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: http://latestpost.pastebin.co.uk/3890

    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?

  2. BPartch
    Member
    Posted 7 years ago #

    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; ?>
    </ul>
    <?php } ?>

    If I have misunderstood or you have more questions just ask. :)

  3. axiomjunglist
    Member
    Posted 7 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic