WordPress.org

Support

Support » Themes and Templates » How to add an categories for a lastest post list.

How to add an categories for a lastest post list.

  • 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.)

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

    @alchymyth

    Forum Moderator

    <?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)

    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’ );

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to add an categories for a lastest post list.’ is closed to new replies.
Skip to toolbar