bbPress

Simple, Fast, Elegant

bbPress support forums » Troubleshooting

Full Content of Most Recent Post on Front-Page?

(46 posts)
  • Started 1 year ago by yottabite
  • Latest reply from jenz
  • This topic is not a support question
  1. i want to display the most recent post, no matter what forum it happens to be from. is that possible?

    i tried doing what you said but maybe i messed it up because i'm getting a mysql syntax error. here is what i have, forgive me if it looks glaringly stupid:

    <?php
    $forum_id = 1;
    $forum_one_topics = $bbdb->get_row("SELECT * FROM $bbdb->topics WHERE forum_id = $forum_id ORDER BY topic_time DESC ") ?>
    <?php
    $forum_one_topic_posts = get_thread( $forum_one_topics->topic_id); ?>
    Re: <a href="<?php topic_link(); ?>"><?php topic_title(); ?></a>
    <span class="gray">
    <a href="<?php get_user_profile_link( $id = 0, $page = 1 ); ?>">
    <?php echo $forum_one_topics->topic_last_poster_name; ?></a> said:</span> <span class="justify"><?php echo $forum_one_topic_posts[0]->post_text;
    ?></span>

    sorry, i'm really trying to get it :/

    Posted 11 months ago #
  2. Sure that's possible. :)

    You want a query that gives you the last post. Forget anything messing around with the forum or the topic. You want the last post, right?

    There's no API function to do this AFAIK, so you will have to use a query. I think the structure could go something like this:

    $latestpost = $bbdb->get_row("
    	SELECT *
    	FROM $bbdb->posts
    	WHERE post_status = 0
    	LIMIT 1
    ");

    And then $latestpost has $latestpost->post_text, poster_id and so on. But unfortunately not filtered, so you'd need to apply all those. Which is a bit nasty.

    But this is all unchecked and unresearched, you'll need to play around with it. :P All this is is a bare start.

    Posted 11 months ago #
  3. ok cool, thank you. it's doing something so that's good :)

    this is what i'm using:

    <?php
    $latestpost = $bbdb->get_row("
    	SELECT *
    	FROM $bbdb->posts
    	WHERE post_status = 0
    	LIMIT 1
    ");
    ?>
    
    <?php echo $latestpost->post_text; ?>

    it's displaying the first post from forum 3 for some reason, not the most recent post. i've posted a few new posts since then in other forums and it never changes on the front page, it still shows that first post from that forum 3. any idea how come?

    (thanks for your help on this)

    Posted 11 months ago #
  4. You'll need to order that query by using ORDER BY post_time DESC. There is no guarantee that the last row of a table is the last row that was added.

    Posted 11 months ago #
  5. yes, that worked, thank you.

    i'm going through the template-functions.php trying to find how to display the last poster's username and his/her profile link, as well as the link to the topic itself but the only ones i can get to work are these:

    <?php echo $latestpost->post_text; ?>
    <?php echo $latestpost->poster_id; ?>
    <?php echo $latestpost->post_time; ?>

    any suggestions? :)

    Posted 11 months ago #
  6. I don't know which ones you had problems with but it's worth noting that some automatically echo and some don't.

    <?php user_profile_link(); ?>
    =
    <?php echo get_user_profile_link(); ?>

    If they're get_anything then you have to echo them yourself, if they don't have get_* then it'll echo on its own.

    [Edit] Also remember most functions don't need a $user_id passed as parameter but won't work in this case unless you do pass it.

    Posted 11 months ago #
  7. er, nevermind me, you're doing it within bbpress...

    Posted 11 months ago #
  8. so to get the last poster's username to display, do you do something like this?

    <?php echo get_user_name($user_id); ?>

    i guess i don't understand the whole passing parameters thing :/

    Posted 11 months ago #
  9. wait, i got this to work to display the name:

    <?php echo get_user_name($latestpost->poster_id); ?>

    and this to make it into a link to the person's profile:

    <a href="<?php user_profile_link($latestpost->poster_id); ?>"><?php echo get_user_name($latestpost->poster_id); ?></a>

    now all i need is to display the topic title and make it a link ... i need help with this one please :)

    Posted 11 months ago #
  10. That's great! Passing parameters is just giving the function some data to work with.

    $latestpost->topic_id is the topic ID. There are probably some functions like topic_title() and link_to_topic() or similar that you can use to get the title and link. They too will need the topic ID passed as a parameter, so if those are the actual functions it could be topic_title( $latestpost->topic_id ); :)

    Posted 11 months ago #
  11. excellent! i got it to work with this just before i checked back for your reply:

    <a href="<?php echo get_topic_link($latestpost->topic_id); ?>"><?php echo get_topic_title($latestpost->topic_id); ?></a>

    i think i understand it better now, thanks again! :D

    Posted 11 months ago #
  12. Cool. :) Can you post the entirety of the code you're using now, in case someone else will be looking through the forums for a full solution?

    Posted 11 months ago #
  13. yes, good call:

    <?php
    $latestpost = $bbdb->get_row("
    	SELECT *
    	FROM $bbdb->posts
    	WHERE post_status = 0
    
    	ORDER BY post_time DESC
    	LIMIT 1
    
    ");
    ?>
    
    Re:
    <a href="<?php echo get_topic_link($latestpost->topic_id); ?>"><?php echo get_topic_title($latestpost->topic_id); ?></a>:<br /><br />
    
    <a href="<?php user_profile_link($latestpost->poster_id); ?>"><?php echo get_user_name($latestpost->poster_id); ?></a> said:
    
    <?php echo $latestpost->post_text; ?>
    Posted 11 months ago #
  14. how does one filter the output for time in this example?

    <?php echo $latestpost->post_time; ?>

    i'd like it to be in the format of ( 'g:i A' )

    ps, my good, good people :)

    how would i turn this link into a link to the latest reply itself instead of just the topic:

    <a href="<?php echo get_topic_link($latestpost->topic_id); ?>"><?php echo get_topic_title($latestpost->topic_id); ?></a>

    Posted 11 months ago #
  15. Turn the time-string into a timestamp to be turned into a time-string.

    <?php echo date( 'g:i A', strtotime( $latestpost->post_time ) ); ?>

    There's a template function that gives you the link to the latest post in the topic. I believe it's called get_topic_last_post_link() but I'm not sure.

    Posted 11 months ago #
  16. If I used:

    <?php
    $forum_id = 1;
    $number_of_topics = 7;
    $forum_one_topics = $bbdb->get_results("SELECT * FROM $bbdb->topics WHERE forum_id = $forum_id ORDER BY topic_id DESC LIMIT 0,$number_of_topics")
    ?>
    <?php
    foreach($forum_one_topics as $topic) : $forum_one_topic_posts = get_thread( $topic->topic_id); ?>

    (as see at the beginning of this topic) - how can I show the initial topic time on the front page instead of the last reply time?

    Posted 2 months ago #

RSS feed for this topic

Reply

You must log in to post.

Code is Poetry.