• Hi I am developing a site for a little league baseball league.

    http://WWW.dunbarbaseball.ca/jmtest

    IN the home page there is a green area where I just want the latest post from the category=league news. The area below I want the next 4 posts excerpts to show up regardless of category.

    is there an easy way to do this? When I set the green area to just give a post from category = league news the area below only gives league news excerpts.

Viewing 1 replies (of 1 total)
  • Don’t know what you are using for code so will give an example

    <?php
    //1 post from league news
    $cat_id = get_cat_ID('league news');
    $args=array(
      'cat' => $cat_id,
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        $dontdup = $my_query->post->ID;
        the_content();
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    
    //now 4 more posts, except for the one we just displayed
    $args=array(
      'post__not_in' => array($dontdup),
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 4,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        the_excerpt();
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
Viewing 1 replies (of 1 total)

The topic ‘selectively Display posts by category’ is closed to new replies.