Show last 5 posts from thread x on a non-vb page (and parse BB)
Note: The arcticle below is based on working with vb3.7.3 PL1 and it's fully functional there. I ought it be functional within the rest of the 3.x range, but I can't guarantee anything.
Introduction This is the first article related to programming I've ever written, so bare with me. While looking for a proper solution myself I have noticed that a lot of people were looking on how to pull posts from a specific thread (not just forum, can use RSS for that) and show either the first x or last x posts from that thread on a non-vb page. On top of that I noticed that in the meantime, which isn't less important, that people were also struggling on how to parse BB Code at the same time. I am not a programmer or anything, but am more than willing to share my knowledge of this, after having ploughed through hundreds of posts and dozens of threads. As I know how frustrating this can be. All credits go to all that contributed through their posts in other threads in order for me to complete this piece of coding. What is not covered? I am going to assume that you are familiar with connecting to databases, even connecting to multiple databases and that you will familiarize yourself with the structure of your 'post' table in your forum's database. If you want information on how to connect to 2 databases within the same page, check php.net on mysql_connect() for more info on that. What is covered? I'll show you what files regarding the interaction with vbulletin are required for fetching the information and parsing BB Code and give you a little comparisson information on what I did with the true/false settings you can do with the parse. Right, lets get started. Required lines of code for vbulletin interaction and parsing BB Code PHP Code:
Don't forget to set your path to your forum! Setting your variables for the Query on the post table I think the code below is obvious. Of course you can replace 'your_forum_db' and 'thread_id' with values you pull from another database, but lets keep it simple here. Also make sure your threadid exists ;) PHP Code:
Now we're going to make sure you get those last 5 posts and we have to set a limit for that. Now there are other way to approach this, but I am planning to keep it simple and basically this is what suits my needs. PHP Code:
Getting the post information based on the limit Now that we know the postcount on thread x, we can go on querying the post table for its contents. PHP Code:
Parsing the BB-code and output the posts Now it's time to get things going, parse the bb-code (and in my case also strip it of quotes) and get the information returned onto your screen. PHP Code:
Next up is the actuall parsing of the BB-Code. Remember when I commented out that line at the beginning of this article? This is why and I urge you to only use this to compare the two lines, do not add them (again): Code:
$parsed_text = $parser->do_parse($text, $do_html, $do_smilies, $do_bbcode, $do_imgcode, $do_nl2br, $cachable); What I am basically telling the parser to do is the following Quote:
Then last but not least, the output to a browser client and we're done. For those who don't want to pickup the bits and pieces, below the full code where everything is put together (again without code for db connection). Full code PHP Code:
Well there you go, connect it to a database, get the PATH to your forum right and put it in a php file and see if it works. Hope this was useful to some people and gives a bit more insight of what is needed to fetch information from post and parse bb-code. And if anyone has suggestions, please be my guest, can only be beneficial to us all :up: |
nice, thank you for sharing.
|
Thank you! I'd gotten as far as pulling posts from the DB but was stuck on parsing the BBcode. Your code worked perfectly.
|
got anything for vB 4.x.x?
|
Quote:
Quote:
|
thanks 4 article
|
thanks for that USEFUL POST
|
Why not do this?
PHP Code:
|
Looks like a working alternative, have you tried it yourself?
|
Quote:
The full SQL would be: PHP Code:
Anyway, there is no reason why this should not work - after all, programing is just a form of mathematics :D |
All times are GMT. The time now is 12:59 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|