bbPress

Simple, Fast, Elegant

bbPress support forums » Themes

1st line of the first post in a topic?

(11 posts)
  • Started 1 year ago by phollo
  • Latest reply from ardentfrost
  • This topic is not a support question
  1. phollo
    Member

    Hi guys,

    Is there a way i can get the first "n" characters of the first post in a topic so i can make them appear in the forum main page, under each topic's title?

    Thanks!
    :)phollo

    Posted 1 year ago #
  2. You mean you want the first X characters or words from a first post?

    This is possible. I am playing with this myself so users of my bbPortal plugin can use a read more button on the portal if they want to. It wil count the first 100 words and then ad a read more link.

    Think this is something you want (without the read more link). This can be done with a plugin and a new function. I haven't got something working yet else I would post it here...

    Posted 1 year ago #
  3. try this..
    create a plugin with this code..

    function your_function_name($where) {
    global $topic;
    return $where . ' AND topic_id = ' . $topic->topic_id;
    }
    function get_first_post_of_current_topic() {
    add_filter('get_latest_posts_where','your_function_name');
    get_latest_posts(1);
    }

    call get_first_post_of_current_topic in the loop where you show tipc name.
    let me know if works.. this is just a hunch

    cheers

    Posted 1 year ago #
  4. phollo
    Member

    so1o thanks for the hint, but unfortunately i don't get any result..

    Posted 1 year ago #
  5. ok..
    try this plugin

    <?php
    function your_function_name($where) {
    global $topic;
    if ($topic)
    return $where . ' AND topic_id = ' . $topic->topic_id;
    else
    return $where;
    }
    function get_first_post_of_current_topic() {
    global $bb_post;
    add_filter('get_latest_posts_where','your_function_name');
    $bb_post = get_latest_posts(1);
    if(count($bb_post) == 1 ) {
    $bb_post = $bb_post[0];
    post_text();
    }
    }
    ?>

    where you want call get_first_post_of_current_topic();

    Posted 1 year ago #
  6. Is there also a way to get a link to the first REPLY in a post? There is a link option to go to the last reply, but i wanta link ti the first reply. So the sec post (if you see them all as posts)

    Posted 1 year ago #
  7. phollo
    Member

    so1o, thanks, that looks better, but it grabs the last post of the topic, not the first one..

    Posted 1 year ago #
  8. phollo
    Member

    ..
    by declaring $bb_post = $bb_post[0]; i assume $bb_post is an array. now, since i see appearing the last post of a topic i tried to substitute that line with $bb_post = end($bb_post), thinking that maybe the actual first post stayed at the end of the array; i still get the last post though.. any other suggestion?

    Posted 1 year ago #
  9. phollo
    Member

    guys, any other suggestion? :s

    Posted 1 year ago #
  10. Sorry, phollo, can't offer any meaningful help here, but I did just want to say that I'm interested in seeing your results.

    Posted 1 year ago #
  11. $first_post = $bbdb->get_results("SELECT * FROM $bbdb->posts WHERE topic_id = $topic->topic_id AND post_position = 1");

    That will give you the post OBJECT... from there you can pull out the text like this:

    echo $first_post->post_text;

    Or since it seems you want to pull out just the first little bit, just use a php string function to make it look and act like you want it to.

    It's not the most eloquent method, but it's certainly simple.

    Posted 1 year ago #

RSS feed for this topic

Reply

You must log in to post.

Code is Poetry.