Forums

[resolved] Change some snippet depending on ID (3 posts)

  1. mauricenaef
    Member
    Posted 2 years ago #

    Hi There

    really having a hard time to figure this out.
    I have a loop showing a certain category of post. Now I need a different pice of code for e certain Post and I can't seem to get it to work

    here Is my code example

    <?php $new_query = new WP_Query(); ?>
    <?php $new_query->query('cat=23&orderby=title&order=asc'); ?>
    <?php while ($new_query->have_posts()) : $new_query->the_post(); ?>
    <h3><?php the_title(); ?></h3>
    <?php the_content(); ?>
    // How to display this code snippet only for post ID 5
    <p>I am Post ID 5</p>
    // And this snippet for the others
    <p>I am not Post ID 5</p>
    <?php endwhile; ?>

    Thanks for any input

  2. Mark / t31os
    Moderator
    Posted 2 years ago #

    Maybe..

    <?php if( $post->ID == 5 ) : ?>
    <p>I am Post ID 5</p>
    <?php else : ?>
    <p>I am not Post ID 5</p>
    <?php endif; ?>
  3. mauricenaef
    Member
    Posted 2 years ago #

    Wow, thanks... that did it!

    Kind regards

Topic Closed

This topic has been closed to new replies.

About this Topic