Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to get the link to the second post?

  • Hi,

    Beneath eacht post there is a line like: Posted 2 days ago #. The # is a link directly to the topic. Now I want to get this link from (to?) the second post, so I can use this link in a plugin. But how to get this link?

    Many thanks

Viewing 12 replies - 1 through 12 (of 12 total)
  • The # is a direct link to that post.

    What are you trying to do in your plugin that needs it?

    I want to link directly to the sec post and show it just like the # link does now. The problem is how to get this # url without modifing any core files.

    Any help is appreciated

    Assuming that by ‘sec post’ you mean the second post.

    Just the second post of any topic or a specific topic or … What’s the significance of the second post? What’s your plugin supposed to do? I’m asking because it’s easier to help someone if you actually know what they’re trying to do.

    If all you want is a plugin that lists links to the second post of every topic, that’s different than say, one that lists the second post of topics about cabbages. They look similar, but they aren’t always :)

    Well it’s a comment link and, at the moment, linking to the last post. I want to change this to link it to the second post since that is the first real comment. I want, from a specified forum, the links of every second post (first real reply) of every topic in that specified forum.

    Current code:

    <?php printf(__('<a href="%1$s">Comments (%2$s)</a>'), get_topic_last_post_link(), get_topic_posts()) ?></div>

    So get_topic_last_post_link(), should be change to the link the second # is generating now…

    Like get_topic_first_reply_link() or something…

    Thanks

    bbPress isn’t, by nature, designed for that. You’re kind of looking for blog functionality in a forum. Looking at the related functions, I see there’s a way to get first and last, but the posts aren’t sequential. Or rather, they are but they aren’t directly consecutive so you can’t just get the first post and add 1. There’s nothing built in, or easily hackable for that.

    I know, that’s why I ask it here :) The forum has to know some way what topics belong to him and in what order, so there must be a way to get it…. the only questions is: how???

    Logically, I’d say start by learning how the ‘loop’ works (look in topic.php) and figure out how to list all posts. From there, you should be able to sort them.


    _ck_
    Participant

    @_ck_

    They are trying to link to the first reply.

    It far easier to inject an anchor at the very bottom of the first post and link to that instead.

    It could be done via a plugin that appends post_text and checks the $bb_post->post_position to see if it’s equal to 1

    If it’s equal to 1 then append <a name="first-reply"></a>

    Then your first reply is always at http ://topic-link-blah-blah#first-reply

    Note that my unread-posts plugin already solves the problem of linking to the first unread reply per user.


    _ck_
    Participant

    @_ck_

    untested theoretical plugin

    add_filter('post_text','first_reply',999);
    function first_reply($text) {global $bb_post;
    if (!is_bb_feed() && (int) $bb_post->post_position==1) {$text.="<a name='first-reply'></a>";}
    return $text;
    }

    Then to get the first-reply link for any topic,

    <?php echo "<a href='".get_topic_link()."#first-reply'>replies</a>"; ?>

    Hi,

    Thanks for the reply, I’ll try your suggested “untested theoretical plugin”. But what does the 999 stand for? Just learning :)


    _ck_
    Participant

    @_ck_

    the number is a filter/action priority, lower numbers execute first, the default is 10

    999 means try to be the last thing to execute on the filter (so the anchor comes last)

    Okay this works. Small question, if it’s not possible I don’t mind, but currently it jumps to the bottom of the first post. So at the top of the page you’ll see: POSTED 10 MONTHS AGO # 111.111.111.111 on your screen

    Is it possible to lower this new “anchor” just underneath this line so that this line of text is not visible anymore? (because its moved up, out of the screen). Just like the # link does now (if you click it, you’ll see what I mean).

    Now people get the feeling they missed a post and scroll up, only to discover that is the first post. It’s just a small thing, but it would be nicer.

    Thanks

Viewing 12 replies - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.
Skip to toolbar