WordPress.org

Ready to get started?Download WordPress

Forums

Current Post not included in Recent post (11 posts)

  1. eronkid
    Member
    Posted 4 years ago #

    Hi there,

    I do have this code that generates the recent post and the output is good.

      <?php query_posts('showposts=5'); ?>
      <?php while (have_posts()) : the_post(); ?>

    • "><?php the_title(); ?>
    • <?php the_excerpt(__('(more…)')); ?>

      <?php endwhile;?>

    Now my problem is that...
    How to exclude the current/latest post from the list...

    and is there a way just to limit the characters of the text rather than using excerpt? Thank you for the time in helping me.

  2. eronkid
    Member
    Posted 4 years ago #

    I think I have posted a wrong code...
    Here's the new one.

    <ul>
    <?php query_posts('showposts=5'); ?>
    
    <?php while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
    
    <?php the_excerpt(__('(more…)')); ?>
    <?php endwhile;?>
    </ul>

    Again, Thank you.

  3. @mercime
    Volunteer Moderator
    Posted 4 years ago #

    In this line:
    <?php query_posts('showposts=5'); ?>
    add the offset to latest post
    <?php wp_query('showposts=5&offset=1'); ?>

  4. eronkid
    Member
    Posted 4 years ago #

    It works, but it also affects the posts in the homepage.

  5. eronkid
    Member
    Posted 4 years ago #

    I don't get it right.
    you change the <?php query_posts into <?php wp_query ?

    and add the &offset=1 value?

    is that add or change into?

    will I changed the line?

  6. @mercime
    Volunteer Moderator
    Posted 4 years ago #

    I should have asked, what theme are you using and which template file are you modifying/or changing the code of? The code above just showed how to offset 1 post (the most recent post from being included).

  7. eronkid
    Member
    Posted 4 years ago #

    I am not changing any theme, I am just placing that php code and I just need some help in editing it, cause I am not a dev.

    BUT my problem is, that code works and your code also but it also takes effect on the main post list, in which my current post becomes invisible.

    I used the php code I posted here on a widget, using PHP EXEC plugin. Cause I wanted it to run on my sidebar, Im customizing my own theme.

    I hope you understand.

  8. eronkid
    Member
    Posted 4 years ago #

    I have seen the problem... I don't know if this code doesn't close its own loop? Cause it continuous on outside it's loop. Can anyone help me with this, thank you.

    <ul>
    <?php query_posts('showposts=5'); ?>
    
    <?php while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
    
    <?php the_excerpt(__('(more…)')); ?>
    <?php endwhile;?>
    </ul>
  9. @mercime
    Volunteer Moderator
    Posted 4 years ago #

    Now I understand where you're coming from. You need a code for sidebar that won't interfere with the other loops or queries in your main content. Ok, so that's a different matter altogether. Here goes:

    <?php
    $the_query = new WP_Query();
    $the_query->query('showposts=4&offset=1');
    while ($the_query->have_posts()) : $the_query->the_post(); ?>
    <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
    <?php the_excerpt(__('(more…)')); ?>
    <?php endwhile; ?>
    </ul>

    Note: per your first post, I have added the offset to 1 which will exclude listing the most recent post in this list you are generating.

  10. eronkid
    Member
    Posted 4 years ago #

    How about just limiting the characters shown? by NOT using excerpt, is there a way around?

  11. @mercime
    Volunteer Moderator
    Posted 4 years ago #

    install this plugin
    http://wordpress.org/extend/plugins/content-and-excerpt-word-limit/
    after which in your excerpt and content tags, you have option of indicating number of characters
    e.g.<?php excerpt('10'); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic