Forums

how to select post based on category (2 posts)

  1. hcvitto
    Member
    Posted 3 years ago #

    hi
    how can i select post based on category?
    i guess i need to use loop and category tags but don't know how!!

    here's what i came up until now:

    <!-- INIZIO DELLA COLONNA CON I CROSS LINK SINISTRA -->
    <div>
    <!-- Start the Loop. -->
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php if ( is_category('crosslink') ) {
    echo 'crosslink';
    } else {
    echo 'other';
    } ?>
    <?php endwhile; else: ?>
    <p>Sorry, no posts matched your criteria.</p>
    <?php endif; ?>
    </div>

    I exptected to see just as many 'crosslink' as my post in such category but what i see is 'other' for each of my post.

    Any help?
    VItto

  2. MichaelH
    Volunteer
    Posted 3 years ago #

    I believe you want in_category rather than the is_category conditional tag.

    Something like:

    <?php if ( is_category(get_cat_ID('crosslink')) ) {

Topic Closed

This topic has been closed to new replies.

About this Topic