WordPress.org

Ready to get started?Download WordPress

Forums

displaying last post, todays posts, and previous posts (19 posts)

  1. ryanoz
    Member
    Posted 7 years ago #

    This is what I need to show on the index page...
    ONLY the last post.
    Then a list of posts from the current day, AND a list of posts before the current day.

    So, to make this easier, here is a screen grab of what I need to do...
    http://www.oswaldtrading.com/images/Picture11.png

  2. Doodlebee
    Member
    Posted 7 years ago #

    I love this idea...maybe this will help? Working great for me!

  3. ryanoz
    Member
    Posted 7 years ago #


  4. ryanoz
    Member
    Posted 7 years ago #

    doodlebee,
    thanks for replying. I couldn't really follow what was going on in the link you posted.
    I did however almost get everything working just how I wanted, YAY!
    Took some time reading thru the docs and testing, but its working. So I figured I would answer my own question here, and maybe it will help someone else.

    So to ONLY show the last entry, pretty simple; just select it from the wordpress admin/options/reading "show at most..."

    To display a list of ONLY the current days entries...
    (without the latest entry)

    <ul>
    <?php $current_month = date('m'); ?>
    <?php $current_year = date('Y'); ?>
    <?php $current_day = date('j'); ?>
    
    <?php query_posts("year=$current_year&monthnum=$current_month&day=$current_day&order=DESC&showposts=10&offset=1"); ?>
    
    <?php rewind_posts(); ?>
    <?php while (have_posts()) : the_post(); ?>
    
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?><br />
    <span><?php the_time('F jS, Y') ?> - <?php wp_link_pages(); ?> <?php comments_number(__('<strong>0</strong> Comments'), __('<strong>1</strong> Comment'), __('<strong>%</strong> Comments')); ?></span></a></li>
    <?php endwhile; ?>
    </ul>

    To show a list of entries made BEFORE the current day...
    (I haven't figured this one out yet! its going to display the same list as above). To get this to work, I would have to figure out how many posts are in the list above, then set that number as the offset for this list. So i'm still working on it, I guess.

    <ul>
     <?php
     $myposts = get_posts('numberposts=5&offset=1');
     foreach($myposts as $post) :
     ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?>
    <span><?php the_time('F jS, Y') ?> - <?php wp_link_pages(); ?> <?php comments_number(__('<strong>0</strong> Comments'), __('<strong>1</strong> Comment'), __('<strong>%</strong> Comments')); ?></span></a></li>
     <?php endforeach; ?>
     </ul>
  5. Doodlebee
    Member
    Posted 7 years ago #

    Well, here, I'll add to this. Query posts is a bit of overkill. Based on what Kafka posted in that previous link I sent, this is what I did, and it works like a charm:

    <?php if (have_posts()) : ?>
    <?php query_posts("showposts=4"); ?>
    <?php while (have_posts()) : the_post();
    
    $postclass = ($post == $posts[0]) ? 'entry-1' : 'entry'; ?>
    
    <div class="post<?php echo $postclass; ?>" id="post-<?php the_ID(); ?>">
    <h2 class="clear"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
    <small><?php the_time('F jS, Y') ?></small></h2>
    
    <div class="entry clear">
    <?php if ($postclass == "entry-1") { the_content('Read More &raquo;');}
    else { the_excerpt_reloaded(30, '', '', TRUE, 'Read More &raquo;', FALSE, 1); } ?>
    </div>
    
    <?php if ($postclass == "entry-1") { ?>
    <p class="postmetadata">Posted @ <?php the_time('g:i a') ?> by <?php the_author() ?> |  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
    
    <?php } ?>
    </div> <!-- /post -->
    
    <?php endwhile; ?>
    
    <?php endif; ?>

    As you can see, it sets the very first entry (most recent) with a class of it's own. That means you can style it however you choose via a stylesheet. I also used "the_excerpt_reloaded" so the smaller older posts show the excerpt of the posts, instead of the post itself.

    Hope that helps you (and/or someone else)!

  6. ryanoz
    Member
    Posted 7 years ago #

    thanks for all the info.
    I have to say though... I don't think this achieves anything
    that I am trying to accomplish :)
    I'm not concerned with HTML or CSS. Once I am able to get the content it can be styled.
    Just trying to display lists <li> of todays posts
    and another list of 5 or 6 posts before today.

    Also, the screen grab in my original post is an actual HTML page, not an image.

  7. Doodlebee
    Member
    Posted 7 years ago #

    I don't think this achieves anything
    that I am trying to accomplish :)

    it doesn't?

  8. ryanoz
    Member
    Posted 7 years ago #

    unfortunately, no it doesn't.
    Take another look at my original screen grab.
    This link you posted shows the latest post
    and previous post from different days.

    Once again... I need 2 lists...
    a list of ONLY today's entries (minus the last entry)
    AND a list of entries made prior to today.

    My previous post explains how to show the last entry,
    and a list of all the other entries made TODAY.

  9. Doodlebee
    Member
    Posted 7 years ago #

    Ah, I see. You're making lists instead of excerpts at the bottom.

    >>Also, the screen grab in my original post is an actual HTML page, not an image.<<

    Looks like an image to me.

    Anyway, you can still use the above, it'll make the one post show and you can style it. For the lists, maybe...

    if the only one you can't get is *before* the previous day, maybe do something like:

    <?php $today = the_time('F jS, Y');
           if ($today < date('F jS, Y')) { ?>
           <ul>
           <li>
    put in your code to display the list of titles, dates and comments
           </li>
           </ul>
    <?php } elseif ($today = date('F jS, Y')) { ?>
    display list of today's posts
    <?php } ?>

    Something like that?

  10. ryanoz
    Member
    Posted 7 years ago #

    Looks like an image to me.

    haha, well... I meant its a screen grab of an actual HTML page.

    Yea... I think this is exactly what I need. Looks like it might work perfect.
    Thanks for hanging in there with me :)

    EDIT: well, this looks like it might be an either/or type setup. Display either today's entries or previous entries. Either way though, I can use it to show both of them.

  11. Doodlebee
    Member
    Posted 7 years ago #

    EDIT: well, this looks like it might be an either/or type setup. Display either today's entries or previous entries. Either way though, I can use it to show both of them.

    Holy crap, you mean it worked? LOL I've shocked myself.

    Well, you *might* be able to take it step further then, and set it using the Loop? Maybe by using your "rewind posts" thing, and removing everything after the "elseif" and placing it into the secondary Loop? I'm not sure what the exact coding would be, but hopefully you get the gist of what I mean. So maybe....

    <?php $today = the_time('F jS, Y');
           if ($today < date('F jS, Y')) { ?>
           <ul>
           <li>
    put in your code to display the list of titles, dates and comments
           </li>
           </ul>
    <?php }

    then end the loop, and begin a second one with:

    <?php $today = the_time('F jS, Y');
           if ($today = date('F jS, Y')) { ?>
    display list of today's posts
    <?php } ?>

    Perhaps that would work? I'm sure there's a better way to do it, but I do know it's not a big deal to put in more than one Loop per page...

  12. ryanoz
    Member
    Posted 7 years ago #

    thanks doodlebee,
    I actually haven't tried this yet, it just looks like it will work or at least gets me going in the right direction.
    I've been styling how these list should look when I get them working :)

    I'll update this posts when I have some results.

  13. ryanoz
    Member
    Posted 7 years ago #

    UUUUUURURUGHGHGHHGHG!
    I can't describe how angry and frustrated I am right now.
    I've been trying to get this to work non-stop for the past
    8hrs! trying different combinations of code, uploading, refreshing! I'm not a programmer and I hate having to pretend to be! I need to get this working, WTF do I do?
    I don't even know where to begin or end with this. I've copied and pasted, deleted, added, and rearranged so many different combinations of PHP/wordpress code my head is spinning.
    So whatever, I'll paste the code that I have.
    This is creating a list of the past 10 entries.
    I only want a list of 4 entries prior to today.

    <ul>
    
    <?php
    $myposts = get_posts('numberposts=10&order=DESC&offset=1');
    $entrydate = the_date('F jS, Y','','', FALSE);
    $todaysdate = date('F jS, Y');
    foreach($myposts as $post) :
    if ($entrydate < $todaysdate) : ?>
    
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?>
    <span><?php the_time('F jS, Y') ?> - <?php wp_link_pages(); ?> <?php comments_number(__('<strong>0</strong> Comments'), __('<strong>1</strong> Comment'), __('<strong>%</strong> Comments')); ?></span></a></li>
    
    <?php else: ?>
    <?php endif; ?>
    <?php endforeach; ?>
    </ul>
  14. Doodlebee
    Member
    Posted 7 years ago #

    This is creating a list of the past 10 entries.
    I only want a list of 4 entries prior to today.

    Well, the last 10 entries is because you have "showposts=10" for $myposts - that's why it's showing 10 - you should change that to 4.

    I think your $entrydate might be wrong, as well. the_date should be "the_time". But I still think it's possible that it's looking at the code and seeing what *todays'* date is, not the date of the post itself. I think you need to query the database and get the_time() from the posts themselves.

    So *maybe* something like...

    <?php
    $myposts = get_posts('showposts=4&order=DESC&offset=1');
    $todaysdate = date('F jS, Y');
    foreach($myposts as $post) :
    if ($post_date < $todaysdate) : ?>

    Maybe that would help?

  15. ryanoz
    Member
    Posted 7 years ago #

    Well, the last 10 entries is because you have "showposts=10"

    I know. Doesn't matter though... if there aren't 10 entries prior to today then it should only show however many of the 10 that are.

    EDIT: oh, and using $entrydate = the_time('F jS, Y'); ?>;
    displays the date on the webpage.
    The last code you posted... displays a list of the the last 5 entries including todays.

    I can't believe its this difficult just to display a list of entries made before the current day. Am I the first one to try and do this? Its got to be documented somewhere in all this WP crap. I must be a total idiot!

  16. ryanoz
    Member
    Posted 7 years ago #


  17. ryanoz
    Member
    Posted 7 years ago #

    Is there any way to get support for this stuff?
    I don't have time to keep trying different combinations over and over when I don't know what I'm doing.
    I guess I need to find out if my hosting provider offers support for WP, cause I need to talk to someone that knows how to get this working.

  18. Doodlebee
    Member
    Posted 7 years ago #

    Is there any way to get support for this stuff?

    This *is* the support for WordPress. WordPress is open source and free for all to use, so it's not a company that makes a profit and can hire support staff. You're at the only place you'll get suppor

    You can get *paid* support by going to the wp-pro list - you can hire someone to just do it for you through there.

  19. ryanoz
    Member
    Posted 7 years ago #

    You can get *paid* support by going to the wp-pro list - you can hire someone to just do it for you through there.

    Awesome! Sounds like a good idea to me!

Topic Closed

This topic has been closed to new replies.

About this Topic