WordPress.org

Ready to get started?Download WordPress

Forums

How do I list older posts by just title and date? (16 posts)

  1. Silvetti
    Member
    Posted 9 years ago #

    Hi there,

    Sorry it seems to be a dau of questions!

    I have just been looking at this site: http://www.456bereastreet.com/ and liked the way that they show older posts. Can this be done in WP? I am running 1.5.1.

    Thank you

  2. Ming
    Member
    Posted 9 years ago #

    As long as the older, shortened posts follow right after the newer posts it's easy to do by having PHP count the number of posts you've displayed. If it's less than 5 (an example number) we'll style them like full posts and if it's more than style them like older posts.

    Here's the loop from the default template. Changes are in bold. You'll have to make this fit with your templates. Let me know if you're having problems with that.


    <?php if (have_posts()) : ?>

    <?php $i = 0; ?>

    <?php while (have_posts()) : the_post(); ?>

    <?php if ($i < 5) { ?>

    // ...WordPress tags to display newer posts...

    else {

    // ...WordPress tags to display older posts...

    <?php } ?>
    <?php $i++; ?>

    <?php endwhile; ?>

    This will only work if the older posts follow the newer posts. If you want to put older posts somewhere else in the page you'll need to do a whole new query and loop.

  3. Silvetti
    Member
    Posted 9 years ago #

    Hi Ming,

    Many thanks for that but I tried what you said and nothing seemed to happen. I added the code and there were no page errors but there was also no older links :)

    I am sure it was me but not sure. I have uploaded my unchanged index here. http://www.nuveautek.com/code.txt

    Again thank you for replying :)

  4. Silvetti
    Member
    Posted 9 years ago #

    scrub that - I forgot I had wp-cache enabled :o)

    c**p now I am getting - Parse error: parse error, unexpected T_ELSE in /home/public_html/news/wp-content/themes/eo_mrk2/index.php on line 32

    Here is the code (now with new code): http://www.nuveautek.com/code.txt

    Any ideas?

  5. Ming
    Member
    Posted 9 years ago #

    Good catch on the cache, I always forget about that too.

    It's my mistake in the above code. The line


    <?php else { ?>

    needs to be changed to
    <?php } else { ?>

    (The first brace is required to close the 'if' part before moving on to the 'else' part)

    Let me know how it goes.

  6. Silvetti
    Member
    Posted 9 years ago #

    Hi there,

    Thanks for the reply :)

    Hmmmm when I try the page now the whole area for older posts is invisiable (not loaded), not sure why though.

    Here is my current code: http://www.nuveautek.com/code.txt

    By the way thank you for staying on this post :)

  7. Ming
    Member
    Posted 9 years ago #

    Hey, do you have a link to a live copy of this page? I'd like to see what html is being written. Guaranteed it's something silly we're missing so we'll track it down eventually :-)

  8. Ming
    Member
    Posted 9 years ago #

    I tested your code and it's working for me. I took your code.txt, renamed it to index.php and put it in themes/default/. I had to remove one or two lines for functions I didn't have but that's all.

    Here's a screenshot http://tylerbrekko.com/temp/nuveautek.png.

    So not sure where the problem lies. But if you send a link to your live I can look at the HTML & CSS.

  9. Silvetti
    Member
    Posted 9 years ago #

    Hi there,

    Thanks for the help. I have been working on this with a couple of other people. So there may be hopefully this has not been double posted :)

    http://www.elyonline.co.uk/

    The strange thing is that there is no sign of that code in the HTML source. Very strange.

  10. Ming
    Member
    Posted 9 years ago #

    The page looks good, nice work on it.

    Ok, so we know that at least 5 posts show on the front page. Change the line
    <?php if ($i < 5) { ?> to < 1. Does that work as expected? (1 new and at least 4 older?)

    If that doesn't help try sticking
    <?php print("new count: $i"); ?> and
    <?php print("old count: $i"); ?> in the new post section and the old post sections respectively. That'll show how many posts are going through the loop and which section they're being processed by.

  11. Silvetti
    Member
    Posted 9 years ago #

    Hi Ming,

    Thanks for that :)

    I have implemented what you said.

    What conclusions do you draw?

    How do I just get the h4 tag saying 'older posts' to show just the once?

    Thanks

  12. Silvetti
    Member
    Posted 9 years ago #

    OK I think I know what the cause is. Should fix shortly :)

    I will keep you posted!

    Thanks

  13. Ming
    Member
    Posted 9 years ago #

    After <?php $i = 0; ?> add
    <?php $displayed = 'no'; ?>

    Then after the <?php } else { ?> add

    <?php if ($displayed == 'no') { ?>
    <h4>Older Entries:</h4>
    <?php $displayed = 'yes'; ?>
    <?php } ?>

    The first time through the older posts the $displayed variable will equal 'no' and so it will display the header. Then it sets $displayed to 'yes' so there's no match and header isn't displayed again.

  14. Silvetti
    Member
    Posted 9 years ago #

    Ming - Thank you so much :) Worked like a charm!

    Now I have to own up to being somewhat of a muppet. I found out why I was not getting those links listed. I had another bloody plugin which I forgot about 'Custom posts per page' - http://wordpress.org/support/6/11211 .

    Sorry about that (me feeling a little embarrassed :))

    Thanks for your patience and your help has been priceless :)

    I have another question and wondered if I should ask it here or email you.

    Its about the links list manager output. I think this may be more complex and would even offer to pay should the need arise.

    My email is: silvett@gmail.com

    Thanks

  15. Ming
    Member
    Posted 9 years ago #

    lol, yeah I've been there before... Well, at least it had a happy ending.

    I sent an email today.

  16. Silvetti
    Member
    Posted 9 years ago #

    sorry Ming - should have been silvetti@gmail.com sorry!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.