Forums

[resolved] Link to second to last post? (8 posts)

  1. nipponese
    Member
    Posted 3 years ago #

    Hi,

    I am trying to create a link to the second to last post.

    I tried:
    <?php previous_post_link( '%link', '<span class="meta-nav">&laquo;</span> %title', in_same_cat, TRUE ) ?>

    But I guess because I am using a <?php the_post() ?> instead of the loop on a category-x.php page, it doesn't work.

    Any help would be appreciated.

  2. Ben Sutcliffe
    Member
    Posted 3 years ago #

    You've got an error in that you can't have TRUE as a value in excluded categories. That's either got to be a number (ie. the category you're excluding) or blank: as you've opted for in_same_cat it's redundant anyway - Codex.

    How do you mean a link to the second to last (penultimate) post - is it a link that is always going to take you to the penultimate post no matter what the post is, or is it that you just want a link to the post (ie. ?p=83783)?

  3. nipponese
    Member
    Posted 3 years ago #

    Whoa, my vocab for the day.

    penultimate post no matter what the post is

    Yeah, this is what I'm trying to achieve.

  4. Ben Sutcliffe
    Member
    Posted 3 years ago #

    Okay, good question... I'll have a think - there might be a plugin that gets the first post, which you'd want to change to the second post.

    Does it need to be the second post from the category a user is browsing or just the second post ever?

  5. nipponese
    Member
    Posted 3 years ago #

    Second post in the category currently being viewed.

    Maybe you're curious, this is my situation: I am making a site for an artist who wants to split his site up into two sections: Art and Writing. So I just made one category Writing, and the other Art.

    So the nav is just a list of categories. When you click one of the category links, he wants it to jump directly into the last post, as I mentioned. Additionally, he wants a button on that same page that will jump to the 'next' posting, which is actually the penultimate post.

    It's a veeeery basic and custom gallery system (which is what most of these artists seem to want).

    I should ask, as an alternative, is there a way to just make clicking the category link jump to the last posts' permalink?

  6. Ben Sutcliffe
    Member
    Posted 3 years ago #

    Then can't you just use next_post_link() to get to the one before it (as you're going backwards)?

    To go straight to the first one you could write the db query yourself - instead of using have_posts() you could query the database and sort the timestamp so that you get the first one at the top? There must be a function where you can call this somewhere...

  7. nipponese
    Member
    Posted 3 years ago #

    It definitely would be cool to find a function for this... Anyone know of anything?

  8. nipponese
    Member
    Posted 3 years ago #

    If anyone has the same problem, this plugin does what I need:
    http://www.dagondesign.com/articles/latest-post-from-each-category-plugin-for-wordpress/

    ...after a little modification.

Topic Closed

This topic has been closed to new replies.

About this Topic