WordPress.org

Ready to get started?Download WordPress

Forums

Only last post, then excerpts? (23 posts)

  1. yurimaanzand
    Member
    Posted 9 years ago #

    Is there a way to show the last post completely and below that the excerpts of the five (or so) following posts on the frontpage?

  2. Michael Bishop

    Posted 9 years ago #

    Yes.
    Before the loop you need to do a query_posts:
    <?php query_posts('posts_per_page=1'); ?>
    After the loop you would do a get_posts:
    <ul>
    <?php
    $posts = get_posts('numberposts=6&offset=1');
    foreach ($posts as $post) :
    ?>
    <li><a href=\"<?php the_permalink(); ?>\"><?php the_title() ?></a><?php the_excerpt(); ?></li>
    <?php
    endforeach;
    ?>
    </ul>

    Where the numberofposts in the get_posts is the number of excerpts you want, plus the number of posts per page (1+5 in this example). So, if you wanted the 3 most recent posts, plus 5 excerpts, you would change the posts_per_page in the query_posts to 3, and change the number postsperpage in the get_posts to 8 and the offset to 3.

  3. Kafkaesqui

    Posted 9 years ago #

    One correction to miklb's reply: You don't need to compensate for the offset parameter in get_posts. If you want 5 post (excerpts) offset by 1, just use:

    get_posts('numberposts=5&offset=1')

  4. Michael Bishop

    Posted 9 years ago #

    Kafkaesqui-I was mistaken. Thanks.

  5. Michael Bishop

    Posted 9 years ago #

    So do you not need the query_posts when using the get_posts?

  6. Kafkaesqui

    Posted 9 years ago #

    You do for the initial post if Options > Reading is not set to 1 post per page. I think most would not wish to change this just to alter the home page display.

  7. yurimaanzand
    Member
    Posted 9 years ago #

    It works!
    Thanks guys - i'm a php-nitwit so this was very helpful.

  8. yurimaanzand
    Member
    Posted 9 years ago #

    Ok - me again.
    How do i show the complete post?
    I mean, i now have the latest post, followed by several excerpts, but is it possible to make the latest post override the 'more'-command, so that is completely visible?

  9. Michael Bishop

    Posted 9 years ago #

    Is the <!--more--> in the post? Are you using the default theme or some elses? That theme may be using the_excerpt instead of the_content inside the loop.

  10. yurimaanzand
    Member
    Posted 9 years ago #

    Yes, the <!--more--> is in every post. So actually i am searching for a way to override the <!--more--> tag for the last post.
    I am using my own theme, based on two or three others, but my index.php (or actually my home.php for the frontpage) is using the_content(__('(more...)')); inside the loop...

  11. Kafkaesqui

    Posted 9 years ago #

    I get what you're trying to do here, but you realize it's like asking for an automatic locking door to never automatically lock except for when you want it to automatically lock...

    To *defeat* the more link you have to work around it, and that means replacing the_content() with some other method of displaying post content. A quick way to do this is to echo $post->post_content, but this leaves out any formatting WordPress takes care of. So to do things right, you want to wrap the formatting/conversion functions around $post->post_content, like the following:

    <?php
    echo wptexturize(convert_smilies(convert_chars(wpautop($post->post_content))));
    ?>

    Looks complicated, but takes care of (I believe all) the formatting features built into WordPress that act on post content.

    Note this will bypass WordPress' filtering API. If you have any plugins that work with post content, you would need to add their functions into that nested group above (ech).

  12. aarons
    Member
    Posted 9 years ago #

    What file needs to be modified in order to have the excerpts show up period?

    I have added a couple of excerpt plugins, unfortunately I have no idea how to use them.

  13. yurimaanzand
    Member
    Posted 9 years ago #

    Thanks Kafkaesqui!
    That trick works fine. I don't have any plugins on the post content, so this is exactly what i need. My blog is here if you would like to see the result. (it's in dutch)

  14. yurimaanzand
    Member
    Posted 9 years ago #

    And here i am again...
    Seems that i do have a plugin on the post content - the lazy-images plugin to be precise...
    I found it here: http://davidseah.com/projects/lzil

    How should i add that function to the nested group as suggested by Kafkaesqui?

  15. Kafkaesqui

    Posted 9 years ago #

    There appear to be two separate functions in that plugin to be called as filters. Try:

    <?php
    echo
    LazyImagePre(
    LazyImagePost(
    wptexturize(
    convert_smilies(
    convert_chars(
    wpautop(
    $post->post_content
    ))))));
    ?>

    (Note I broke up the code into lines for readability, but either this way, or as one line like above, will work.)

  16. yurimaanzand
    Member
    Posted 9 years ago #

    Thanks again!

  17. Kafkaesqui

    Posted 9 years ago #

    Note to future readers of this thread

    I've come to realize there's a simpler method for running all filters on a post's content, and one shouldn't need worry over plugin filters, etc. So instead of the complicated function nesting above, use this:

    <?php
    echo apply_filters('the_content', $post->post_content);
    ?>

  18. nhall
    Member
    Posted 8 years ago #

    I was looking over this thread. I have been trying to display the two most recent posts, only as excerpts. This was simple,

    <?php query_posts('posts_per_page=2'); ?>

      <?php
      $posts = get_posts('numberposts=2');
      foreach ($posts as $post) :
      ?>

    • \"><?php the_title() ?><?php the_excerpt(); ?>
    • <?php
      endforeach;
      ?>

    easy enough, I still have a few questions though. Where is the excerpt limit declared. For example, where is it set how many characters or words are displayed before the post is cut off. Also, how do I remove the "[...]" when the excerpt is used.

    Thanks
    Nick

  19. Kafkaesqui

    Posted 8 years ago #

    Nick, you may be interested in this recent thread:

    http://wordpress.org/support/topic/41856

    Especially where I hit on (a) here:

    http://wordpress.org/support/topic/41856#post-235181

    The wp_trim_excerpt function mentioned is also where the excerpt length is set. Another option may be my plugin:

    http://guff.szub.net/the-excerpt-reloaded/

  20. d1srupt3r
    Member
    Posted 8 years ago #

    I am so confused. I don't know where to start first. Can someone please tell me what file I should edit first?

  21. Kafkaesqui

    Posted 8 years ago #

    Your active theme's index.php (Index) would be a good place to start, if you're looking to alter the diplay of your blog on its home page.

  22. Adapt-a-put
    Member
    Posted 8 years ago #

    I used this method, but comments_popup_links for the excerpts does not work. Is this a bug? Or am I doing something wrong?

  23. Adapt-a-put
    Member
    Posted 8 years ago #

    It's rather urgent.

Topic Closed

This topic has been closed to new replies.

About this Topic