WordPress.org

Ready to get started?Download WordPress

Forums

How to add an categories for a lastest post list. (3 posts)

  1. bryanlean
    Member
    Posted 2 years ago #

    How to add an categories for a lastest post list so it just show the lastest post of a categories:

    [please mark any code with the 'code' button]

    <ul>
       <?php query_posts( 'showposts=5' );
          if ( have_posts() ) : while ( have_posts() ) : the_post();?>
    
    <li> <a>"><?php the_title(); ?></a> </li>
       <?php wp_reset_query(); ?>
    </ul>

    As we know the code above show the all lastest post in list format. While in this case, I'm putting this latest list in my footer and separate it into 3 parts:

    1. lastest post of categories 1
    2. lastest post of categories 2
    3. lastest post of categories 3

    How could I suppose to add categories in the code above ? ( the code will repeat 3 tmes for 3 different categories that for sure.)

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    <?php $cats = array(5, 37, 98); //category ids
    foreach( $cats as $cat ) :
    $catid = $cat->term_id;
    query_posts( 'showposts=5&cat='.$catid );
          if ( have_posts() ) : ?>
      <ul>
      <?php while ( have_posts() ) : the_post();?>
    
      <li> <a/*needs repairing*/>><?php the_title(); ?></a> </li>
    
       <?php endwhile; ?>
      </ul>
    <?php endif;
    endforeach;
    wp_reset_query(); ?>

    (untested)

  3. bryanlean
    Member
    Posted 2 years ago #

    Is it possible to do it using the simple code below ?
    The code you provide are complicated for me to understand.
    <?php query_posts( 'catergories_name=Catergories1&showposts=5' );

Topic Closed

This topic has been closed to new replies.

About this Topic