Info
- 46 posts
- 11 voices
- Started 5 years ago by yottabite
- Latest reply from jenz
- This topic is not a support question
Full Content of Most Recent Post on Front-Page?
-
- Posted 4 years ago #
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 4 years ago #
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
$latestposthas$latestpost->post_text, poster_idand 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 4 years ago #
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 4 years ago #
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 4 years ago #
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 4 years ago #
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_anythingthen you have to echo them yourself, if they don't haveget_*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 4 years ago #
er, nevermind me, you're doing it within bbpress...
-
- Posted 4 years ago #
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 4 years ago #
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 4 years ago #
That's great! Passing parameters is just giving the function some data to work with.
$latestpost->topic_idis the topic ID. There are probably some functions liketopic_title()andlink_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 betopic_title( $latestpost->topic_id );:) -
- Posted 4 years ago #
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 4 years ago #
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 4 years ago #
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 4 years ago #
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 4 years ago #
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 4 years ago #
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?
-
You must log in to post.