• Resolved pbowman

    (@pbowman)


    I was wondering how I could show only 1 or 2 of my most recent posts and then just have a list of the other recent post titles on the main page.

    For example: http://gluedideas.com/

    Is there just a simple piece of code I can insert into the index file?

    Thanks.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Try this

    <?php if (have_posts()) : ?>
    <?php $count = 0; ?>
    
    <?php while (have_posts()) : the_post(); ?>
    <?php $count++; ?>
    
    <?php if ($count <= 2) : ?>
    
    <h2><a class="permalink" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    <?php the_title(); ?></a></h2>  
    
    <?php the_content(); ?> // display the full content of the first two posts only
    
    <?php else : ?>
    
    <h2><a class="permalink" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">       <?php the_title(); ?></a></h2>  // Just the permalinks
    
    <?php endif; ?>
    
    <?php endwhile; ?>
    
    <?php else : ?>
    
    <?php endif; ?>
    Thread Starter pbowman

    (@pbowman)

    Thanks!

    cool code. thanks.

    richarduk

    I incorporated your code above, and it is great! Just wondering if there is any way to modify it so when the user clicks on the Next link at the bottom of each page he/she sees a continuation of the list of titles only. Right now, with my WordPress options set to display 8 entries per page, the user sees the first 2 entries in full, followed by a list of the next 6 post titles at the top of each page when he/she clicks Next.

    Thanks!
    Barbara

    Barbara
    That’s the problem 🙂

    It’s beyond my capabilities.

    The only alternative is the following code (I haven’t tested it but it’s roughly right), and passing some variable into the query_string to change the offset dynamically according to which page you’re on. Again, I don’t know how to do that 🙂

    This will show post titles from posts 5-10
    A separate loop above it would just have the first five posts as full posts

    <?php query_posts($query_string . '&offset=5&showposts=10'); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>  
    
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    <?php the_title(); ?></a></span>   on   <span class="post-information">  <?php the_time('j/m/Y') ?> by   <?php the_author();?>
    <?php if ( comments_open() ) : ?>
    <?php comments_popup_link('No Comments - be the first!', '1 Comment so far - read it and leave your own! ', '%  Comments - read them and leave your own!', 'comment-link', 'Sorry, no further comments on this post'); ?> 
    
    <?php endif; ?>  
    
    <?php endwhile; ?>
    <?php else : ?>
    <?php endif; ?>

    If you figure anything out let me know 🙂

    Got 2 possibilities – working from the code above.

    1. If there is a code combo or character for infinity or “all thereafter,” etc., then couldn’t we replace the 10 in the first line with that symbol or code to indicate “from post #5 forward”?

    2. What about this… I have a category called ~All (using the tilde character to throw it to the end of the displayed list of Categories that display next to the post title) I select for all posts, together with any other applicable categories. I do that so I can show a “list” version of all posts with just the date, title and excerpt. That way my users can choose if they want to read the first few posts, or go straight to a list of all posts. Is there anyway to replace the NEXT link that falls at the bottom of that first page (or remove that link altogether, and insert a regular, old fashioned hyperlink) that when selected would take the user to the ~All category “list” page, aka cat=18, but do so with a query that would show all BUT the first, say, 5 posts (if 5 is what you show on page 1).

    Thoughts?

    Thanks
    Barbara

    I can see your ideas, and I’ve posted the general question here.

    Hope it helps us both 🙂

    http://wordpress.org/support/topic/197311?replies=1#post-831040

    this is awesome, but is there some way to do the same in a category ?
    say, i have a category-10.php file so when that category is viewed,
    the latest blog entry in full, and the rest as titles. ?
    ive been trying to make this work but keep getting errors.

    ignore me, i got it working within the category pages.
    Cheers, great code thanks.

    Thanks for this code – exactly what I was looking for!

    hi please if anyone can tell me step by step where to put this CODE:

    ///////////////////////////////////////////////////////////////////

    <?php if (have_posts()) : ?>
    <?php $count = 0; ?>

    <?php while (have_posts()) : the_post(); ?>
    <?php $count++; ?>

    <?php if ($count <= 2) : ?>

    <h2>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”>
    <?php the_title(); ?>
    </h2>

    <?php the_content(); ?> // display the full content of the first two posts only

    <?php else : ?>

    <h2>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”> <?php the_title(); ?></h2> // Just the permalinks

    <?php endif; ?>

    <?php endwhile; ?>

    <?php else : ?>

    <?php endif; ?>

    //////////////////////////////////////////////////////////////////////

    THANK YOU.

    It replaces the existing loop, which starts off with <?php if (have_posts()) : ?> e.g. in your category.php template

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Show only 1 latest post and then just titles of recent posts’ is closed to new replies.