|
在网站首页调用MyBB论坛的帖子 [教程] [待翻译]
|
|
2009年05月28日, 00:12
|
|||
|
|||
|
在网站首页调用MyBB论坛的帖子 [教程] [待翻译]
I have written a PHP class which displays last X posts or threads. It will work independent from place which it is ececuted from (it must be placed at least in the same server as MyBB instalation is). Access to "inc/config.php" is neccessary (database login data are got from it). The most convinient is to save class as eg. "MyBBLatest.class.php" and include it in your site. Class will not display anything in case of database errors, so user will not see any unexpected errors. Feel free to use it. I thought GNU GPLv2 license would fit, but don't mind if you have not got bad intentions.
Bellow you can find manual and some usage examples.Manual __constructor(string $mybb, string $url) It executes while class is initialized. First argument contains relative path to main directory of MyBB instalation. For example if your site is placed in root directory and forum is installed in "board" directory just enter "board" here. If page in which you want to display posts/threads is placed in the same directory as board you do not have to enter anything. Just remember about trailing slash! Default: NULL Second argument contains absoute board URL (eg. http://www.siteaddress.com/board/). It is the only argument which is neccessary. Just remember about trailing slash! threads(integer $many, boolean $lastpost, integer $fid) Displays sorted by date threads list. First argument says how many threads has to be displayed. Default: 10 Second argument decides if thread link has to direct to last or first post. Default: false Third argument says from which forum ID threads have to be displayed. If NULL it gets threads from whole board. Default: false posts(integer $many, integer $fid) First argument says how many posts has to be displayed. Default: 10 Second argument says from which forum ID posts have to be displayed. If NULL it gets posts from whole board. Default: false Usage examples I assume that you have saved the class in "MyBBLatest.class.php" in the same folder in which is placed the file in which you want to use it. So let's include the class: PHP 代码: require_once('MyBBLatest.class.php'); Now you have to initialize class: PHP 代码: $mybb = new MyBBLatest('board', 'http://www.com/board/'); Now you are ready to display latest threads and posts. The most simple way is to make list of 10 latest threads and posts from whole board: PHP 代码: echo $mybb->threads();You can add some HTML if you want: PHP 代码: <h3>Latest threads</h3>You can display latest 5 threads from forum of ID 2 which direct to last post: PHP 代码: <h3>Latest threads from X</h3>In the same way you can do with posts: PHP 代码: <h3>Latest posts from forum X</h3>FAQ Q: With which version of MyBB class works? A: I've tested it with 1.4. Q: Why class doesn't allow user to choose look of list easily? A: Because I made this for really PHP beginners. It is very simple to use and that had to be. It is first release and I'm sure I'd include formating in the future.Q: Why don't you keep properly order of arguments in contructor? A: Because I'm sure that almost everybody will use first argument. ![]() Q: Why don't you use MySQLi as database driver? A: Because it is much slower than standard MySQL. I've tested it! It takes about 1.35x more time. And that's it. I am looking forward to your feedback and suggestions. If you need some help with this just ask.Class content PHP 代码: <?php |
|||
|
2010年05月13日, 09:18
|
|||
|
|||
|
RE: 在网站首页调用MyBB论坛的帖子 [教程] [待翻译]
谢谢admin淘到这么性感的class
在wordpress上运用成功 |
|||
|
2010年05月13日, 15:29
|
|||
|
|||
|
RE: 在网站首页调用MyBB论坛的帖子 [教程] [待翻译]
呵呵,看着这时间,我就觉得可悲~
刚淘到,还没来得及翻译,就与世隔绝了 |
|||
|
|