• I’m sure this has been answered, but I can’t seem to find it…

    I would like to have the first 5 posts of my blog show the summaries of the posts (using the more tag) and the rest of the posts be a list of titles. How would I go about doing this?

    Thanks ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • Here’s one example:

    <?php
    $count = 0;
    $args=array(
      '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(); ?>
    
        <?php
    
      $count++;
        if ($count <= 5) {
          the_content();
        } else {
          the_title();
        } 
    
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Related:
    Customizing_the_Read_More

    Hi,

    You could also use 2 loops using wp_query to get what you want. You could do something like this for the first loop:

    <!-- First 5 posts to show summaries -->
    <?php $summary = new WP_query('showposts=5'); ?>
    <?php while ($summary->have_posts()) : $summary->the_post(); ?>
    <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    <?php the_excerpt(); ?>
    <?php endwhile; wp_reset_query(); ?>
    
    <!-- Next 5 posts show full text -->
    <?php $full = new WP_query('showposts=5'); ?>
    <?php while ($full->have_posts()) : $full->the_post(); ?>
    <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    <?php the_content(); ?>
    <?php endwhile; wp_reset_query(); ?>

    Let me know if that works for you.

    Thread Starter shanafourde

    (@shanafourde)

    Thanks for the help, but I’m having problems knowing where to put the code. I probably should have been more specific, but I am making a page of posts where the posts listed would only be from one category. Here’s my current code:

    <?php
    if (is_page() ) {
    $category = get_post_meta($posts[0]->ID, 'category', true);
    }
    if ($category) {
        $cat = get_cat_ID($category);
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $post_per_page = -1; // -1 shows all posts
        $do_not_show_stickies = 1; // 0 to show stickies
    
    $args=array(
       'category__in' => array($cat),
       'showposts' => $showposts,
       'caller_get_posts' => $do_not_show_stickies
       );
    $my_query = new WP_Query($args);
    ?>
        <?php if( $my_query->have_posts() ) : ?>
            <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
                <?php
                //necessary to show the tags
                global $wp_query;
                $wp_query->in_the_loop = true;
                ?>
    <?php
    global $more;
    $more = 0;
    ?>
    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                        <h1 class="entry-title"><?php the_title(); ?></h1>
                        <div class="entry-meta">
                            <?php twentyten_posted_on(); ?>
                        </div><!-- .entry-meta -->
                    <div class="entry-content">
                        <?php the_content('<br /><span id=readmore>Read more...</span>'); ?>
                    </div>
                </div>
            <?php endwhile; ?>
        <?php else : ?>
            <h3 class="center">Not Found</h3>
            <p class="center">Sorry, but you are looking for something that isn't here.</p>
            <?php get_search_form(); ?>
        <?php endif;
    }  // if ($category)
    ?>

    Hi again,

    So, are you on a category page template when you want this functionality? And, what file is the code above from? Do you have an example (url) of the page? Sorry to ask so many questions but I’m trying to understand what you want to accomplish. Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How do I show first 5 posts as summaries and the rest as titles?’ is closed to new replies.