MyBB Community Forums

Full Version: Latest threads/posts on your site
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7
hmm ok I'll try it again
Marine is my code right?

<?php
require_once('MyBBLatest.class.php');
$mybb = new MyBBLatest('forum', 'http://www.mywebsite.com /forum/');
echo $mybb->threads();
echo $mybb->posts();
?>
Hello hmm Do I need to put the class content inside the body?

like for example

<body>
class content here
</body>


or I will just paste exactly the class content code that is posted on the 1st page?


Don't know anything about php sorry.
Oh I finally solved it! I tried putting a slah on the forum and it works!

<?php
require_once('MyBBLatest.class.php');
$mybb = new MyBBLatest('forum/', 'http://www.mywebsite.com /forum/');
echo $mybb->threads();
echo $mybb->posts();
?>


Thanks!
whatever I do I get a blank white page without having any error. Not even an error message. web page just like have nothing. I have tried using localhost with php v 5.2. here is the coding I used at last:

<?php
require_once('MyBBLatest.class.php'); 
$mybb = new MyBBLatest('mybb', 'http://localhost/mysite/mybb/'); 
echo $mybb->threads();
echo $mybb->posts();
<h3>Latest threads</h3>
echo $mybb->threads();
<h3>Latest posts</h3>
echo $mybb->posts(); 
<h3>Latest threads from X</h3>
echo $mybb->threads(5, true, 2); 
<h3>Latest posts from forum X</h3>
echo $mybb->posts(5, 2);
/**
* This class can display latest threads or posts
* formated in unordered list (<ul/>)
* It doesn't depend on place where script is being run
* just initialize class and execute proper method
* 
* @author Mariusz "marines" Kujawski <[email protected]>
* @link http://marines.jogger.pl/
* @version 0.1
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
class MyBBLatest {
   // mysql db handler
   private $db;
   // tables prefix
   private $prefix;
   // url to mybb
   private $url;
   /**
   * constructor
   *
   * @param string $mybb path to MyBB instalation
   * @param string $url URL of MyBB instalation
   * @return boolean
   **/
   public function __construct($mybb = 'mybb', $url='http://localhost/mysite/mybb') {
      // include mybb config file
      @include('./' . $mybb . 'inc/config.php');
      // db connect
      $this->db = @mysql_connect($config['database']['hostname'], $config['database']['username'], $config['database']['password']);
      // db choose
      @mysql_select_db($config['database']['database'], $this->db);
      // stop executing if db connection isn't availible
      if (!$this->db) return false;
      // set db prefix
      $this->prefix = $config['database']['table_prefix'];
      // set base url of mybb
      $this->url = $url;
      // return
      return true;
   }
   /**
   * display latest threads
   *
   * @param integer $many indicates how many threads have to be retrieved from database
   * @param boolean $lastpost indicates whether link has to direct to last post in thread
   * @param integer $fid ID of forum which threads have to be retrieved from
   * @return string list of threads
   */
   public function threads($many = 10, $lastpost = false, $fid = false) {
      // forum id select
      if ($fid) {
         $where = 'WHERE `fid` = ' . $fid;
      }
      if ($lastpost) {
         $last = '&action=lastpost';
      }
      // initialize temporary var
      $tmp = '<ul class="last-threads">';
      // select data
      $query = @mysql_query('SELECT `tid`, `subject` FROM `' . $this->prefix . 'threads` ' . $where . ' ORDER BY `dateline` DESC LIMIT ' . $many);
      // check if query has result
      if (!$query) return false;
      // collect data into list
      while ($row = mysql_fetch_array($query)) {
         $tmp .= '<li><a href="' . $this->url . 'showthread.php?tid=' . $row[0] . $last . '">' . $row[1] . '</a></li>';
      }
      $tmp .= '</ul>';
      // return list of threads
      return $tmp;
   }
   /**
   * display latest posts
   *
   * @param integer $many indicates how many posts have to be retrieved from database
   * @param integer $fid ID of forum which posts have to be retrieved from
   * @return string list of posts
   */
   public function posts($many = 10, $fid = false) {
      // forum id select
      if ($fid) {
         $where = 'WHERE `fid` = ' . $fid;
      }
      // initialize temporary array
      $tmp = '<ul class="last-threads">';
      // select db data
      $query = @mysql_query('SELECT `pid`, `tid`, `subject` FROM `' . $this->prefix . 'posts` ' . $where . ' ORDER BY `dateline` DESC LIMIT ' . $many);
      // check if query has result
      if (!$query) return false;
      // collect data into list
      while ($row = mysql_fetch_array($query)) {
         $tmp .= '<li><a href="' . $this->url . 'showthread.php?tid=' . $row[1] . '&pid=' . $row[0] . '#pid' . $row[0] . '">' . $row[2] . '</a></li>';
      }
      $tmp .= '</ul>';
      // return posts
      return $tmp;
   }
} // MyBBLatest end
?>

my board installed location is: localhost/mysite/mybb

I use this part :
require_once('MyBBLatest.class.php'); 
$mybb = new MyBBLatest('mybb', 'http://localhost/mysite/mybb/'); 
echo $mybb->threads();
echo $mybb->posts();
<h3>Latest threads</h3>
echo $mybb->threads();
<h3>Latest posts</h3>
echo $mybb->posts(); 
<h3>Latest threads from X</h3>
echo $mybb->threads(5, true, 2); 
<h3>Latest posts from forum X</h3>
echo $mybb->posts(5, 2);
in a separate php file to connect however it gives an error in line 8.

This coding is a grate work if it works. Please help me make it real, and I m still new to myBB and I started to use this forum just 2 days ago. Some instructions make me confused!!. PLEASE PLEASE help me to make it a real, Please tell me step by stem more clearly than in your original instructions.

Thanks in advanced!Smile
hmm is there a way also to get the username of the one post it and date he posted it?

Thanks again!
marines, have you found out why the updating stops after upgrading the main script?
it's very strange. i've done upgrade 1.4.4 -> 1.4.5 -> 1.4.6 -> 1.4.7 while using my class and it worked great every time. :/

all in all i'm rewriting it to give you more power and features. :>
It suddenly started updating again tonight! The only difference I can think of is that someone had started a new topic instead of just replying to old ones.
My website is in Drupal and is in a different host than my Forum. What can I do?
Is it possible to display the author next to the post and thread?
Out of curiosity, does this check the user group of the person? I don't want admin threads to show on the front page for the world to see. Great addon! This works great with joomla!

Also, is there a way to show subforums in a forum? Say I have my structure like:

General Talk (fid = 1)
-> Chit Chat (fid = 2)
-> Greetings (fid = 3)

Would there be a way to pull any threads from the parent forum or would I have to list all of the child forums?
could someone put the full code here

and tell me where to upload it ?
Pages: 1 2 3 4 5 6 7