Is there any way to make a function, say: "get_latest_topic", or simply limit the "get_latest_topics" function to display only the latest topic, but also include the full post?
If not, there may be some other way that I am missing in order to add the content of the latest post to the frontpage, without going all-out and using Worpress for this view.
Thanks in advance!
bbPress support forums » Troubleshooting
Full Content of Most Recent Post on Front-Page?
(46 posts)-
Posted 1 year ago #
-
OK I've figured it out.
I used RSS2HTML, and got the results I needed.
For an example, checkout:
http://forum.blandname.com
Basically, you just include the RSS2HTML.php file in front-page.php, set the template location in the RSS2HTML.php file, and pick how many entries you'd like to have displayed.
To play with the look and feel, you can use the sample-template.html file, and tweak 'til your heart's content.Posted 1 year ago # -
This is a really nice idea. I'll work on getting some convenience functions written for the next "major" release.
Posted 1 year ago # -
I love this, can you explain more detailed (for us noobs) what you did and what you added, changed? Step by step? Can't get this to work with the small details you gave!
Thx
Posted 1 year ago # -
Got it to work, but I see all 35 feeds, where to change that I also only see the last posted topic (and NOT the replies)
Sec, is it possible to only show the last 10 topics (and not the replis on them) from a certain forum? So I only see the last 10 topics from forum with id 1
Thx
Posted 1 year ago # -
you can use this
$topics = get_latest_topics( $forum_id);but this will give you number of topics/page that you set in your config
to get just 10 topics from the forum
$topics = $bbdb->get_results("SELECT * FROM $bbdb->topics WHERE forum_id = $forum_id ORDER BY topic_time DESC LIMIT 0,10")Posted 1 year ago # -
Oke and in what file do I put this? And also where do I put the 1? (1 = forum id)
Sorry I am noob :)
Posted 1 year ago # -
you can put this where you want to display the 10 topics from the forum.. if you want to display it on frontpage then you put it in template for frontpage...
note that the variable names will need to be changed as there are lot of global variables by the same names.. give some unique variable names
Posted 1 year ago # -
<?php $topics = $bbdb->get_results("SELECT * FROM $bbdb->topics WHERE forum_id = $forum_id ORDER BY topic_time DESC LIMIT 0,10") ?> gives me a error:
bbPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY topic_time DESC LIMIT 0,10' at line 1]
SELECT * FROM bb_topics WHERE forum_id = ORDER BY topic_time DESC LIMIT 0,10Posted 1 year ago # -
As you can see in the sql.. you have not defined your $forum_id.. before you call the sql define $forum_id which is the id of the forum for which you want to display the topics..
let me know
Posted 1 year ago # -
Ow I forgot the forum_id...
K I now have this in frontpage.php:
<?php
$forum_id = 1;
$topics = $bbdb->get_results("SELECT * FROM $bbdb->topics WHERE forum_id = $forum_id ORDER BY topic_time DESC LIMIT 0,10") ?>This takes away the error but doesn't display anything either..
Greetz The Noob :)
Posted 1 year ago # -
sorry Null .. but this is the core code.. that will give you the topics..
you will have to write a loop to display the topics eg:
$forum_id = 1;
$forum_one_topics = $bbdb->get_results("SELECT * FROM $bbdb->topics WHERE forum_id = $forum_id ORDER BY topic_time DESC LIMIT 0,10")
foreach($forum_one_topics as $topic) :
?>
<a href="<?php topic_link(); ?>"><?php topic_title(); ?></a>
<?php
endforeach;again: i warn watch where you put it. there are a lot of global variables. dont put in place where you are displaying other topics and stuff
Posted 1 year ago # -
Made some changes, but this works:
<?php
$forum_id = 1;
$forum_one_topics = $bbdb->get_results("SELECT * FROM $bbdb->topics WHERE forum_id = $forum_id ORDER BY topic_time DESC LIMIT 0,10") ?>
<?php foreach($forum_one_topics as $topic) :
?>
<a href="<?php topic_link(); ?>"><?php topic_title(); ?></a><br />
<?php endforeach; ?>but it doesnt show the typed text only the title of the forum. What to add to also show the typed text (NOT the replies ofcourse)
Many thx
Posted 1 year ago # -
<?php
foreach($forum_one_topics as $topic) :
$forum_one_topic_posts = get_thread( $topic->topic_id);
?>
<?php topic_title(); ?><br/>
<?php
echo $forum_one_topic_posts[0]->post_text;
endforeach;
?>Posted 1 year ago # -
Perfect thank you so much
One more question, this way I can also add things like topic_poster right?
Can you give me one more excample of how to add the topic poster to this code as well? I think I get the hang of this and can figure things like topic_time etc out myself if I get that last part I asked!
Greetz
Posted 1 year ago # -
you can do
echo get_user($topic->topic_last_poster);EDIT:
Oops, better way
echo $topic->topic_last_poster_name;Posted 1 year ago # -
Thank you for your help!
Posted 1 year ago # -
no problem
Posted 1 year ago # -
Hi,
I am stuck again. I wanted to split the code to the php part and the template part. I did this:
In index.php I've added (right after
require('./bb-load.php') ;:$forum_id = 1;
$number_of_topics = 10;
$forum_one_topics = $bbdb->get_results("SELECT * FROM $bbdb->topics WHERE forum_id = $forum_id ORDER BY topic_time DESC LIMIT 0,$number_of_topics")In front-page.php I've added:
<?php
foreach($forum_one_topics as $topic) :
$forum_one_topic_posts = get_thread( $topic->topic_id); ?>
<a href="<?php topic_link(); ?>"><?php topic_title(); ?></a>
<?php echo $topic->topic_last_poster_name; ?><br/>
<?php echo $forum_one_topic_posts[0]->post_text;
endforeach;
?>But this results in errors on the index.php file:
parse error, unexpected T_STRING on the first line after the code I've put in the index.php file.What am I doing wrong?
Posted 1 year ago # -
Fixed it. For some reason putting
$forum_one_topics = $bbdb->get_results("SELECT * FROM $bbdb->topics WHERE forum_id = $forum_id ORDER BY topic_time DESC LIMIT 0,$number_of_topics")
in index.php gives the error, but placing it into front-page.php fixes it, no errors and it works...Posted 1 year ago # -
Hi,
Can some kind soul walk me through how to acheive this?
Cheers!
Posted 1 year ago # -
awesome, how would i get the poster's name to become a link to their profile?
Posted 11 months ago # -
I don't know off the top of my head. What I'd do in this case, as for pretty much every question that's asked, is open my copy of bbPress and look around in the files. So that sort of thing sounds like a template tag, so I'd look at bb-includes/template-functions.php, then search for "profile_link" or a couple other similar terms if I couldn't find it.
This time I tested it and searching for "profile_link" will pretty quickly get you the function you want. But finding out what you need is something you can pretty easily do yourself most of the time. :)
(Not that there's a problem with you asking anything, this is just teach-a-man-to-fish thinkin'.)
Posted 11 months ago # -
i hear what you're saying but believe me, i tried my damndest to figure it out myself before i posted (as i do before all my questions). the problem is i don't really understand the syntax of php code just yet so i don't know how to use the get_user_profile_link(); function in this particular example (getting the profile link of the last poster from the entire messageboard onto the front page, it's a little confusing). if you can give me some help on this one, i'd appreciate it.
Posted 11 months ago # -
i have another question about the most recent post on the front page. i got it working great from what was written in this post. however, i then deleted a forum (from position 0) and once i did that, an error appeared where the text from the most recent post used to be:
Warning: Invalid argument supplied for foreach() in /Library/WebServer/Documents/bb-templates/superbold/front-page.php on line 13
any thoughts on how i can correct this and make it work again?
Posted 11 months ago # -
$topic->topic_last_posteris the ID of the last poster to the topic.user_profile_link( $user_id )echoes the url of the user's profile. You'd do something like this I think:<a href="<?php user_profile_link( $topic->topic_last_poster ); ?>"><?php echo $topic->topic_last_poster_name; ?></a>Posted 11 months ago # -
thank you, i will try that.
any idea about the "invalid argument" error i'm getting?
Posted 11 months ago # -
What does it say at /Library/WebServer/Documents/bb-templates/superbold/front-page.php on line 13? Also the significant surrounding lines. Would be kind of useful to know.
Posted 11 months ago # -
sure, here is line 13:
foreach($forum_one_topics as $topic) :and here is the surrounding stuff:
<h2><?php _e('Latest Post'); ?></h2> <?php $forum_id = 1; $forum_one_topics = $bbdb->get_results("SELECT * FROM $bbdb->topics WHERE forum_id = $forum_id ORDER BY topic_time DESC LIMIT 0,1") ?> <?php foreach($forum_one_topics as $topic) : $forum_one_topic_posts = get_thread( $topic->topic_id); ?> Re: <a>"><?php topic_title(); ?></a> <span class="gray"> <a>"> <?php echo $topic->topic_last_poster_name; ?></a> said:</span> <span class="justify"><?php echo $forum_one_topic_posts[0]->post_text; endforeach; ?></span>Posted 11 months ago # -
$forum_one_topicsis not an array which is why it's failing (although I'm surprised it's not).Do you actually want the 1 latest topic from forum 1? Then use
$bbdb->get_row()instead ofget_results()and stop treating it as an array (basically, just take out theforeachpart since you don't have several, and replace$topicwith$forum_one_topics).If you want all the topics from forum one, then take out the LIMIT 0, 1 bit from the query which as I understand it would give you only one result.
Also, you have some malformed HTML just under
span gray.Posted 11 months ago #
Reply »
You must log in to post.