Location: PHPKode > scripts > BlogHelper > ViewBlog.inc
<?
  // ViewBlog.inc
  $yourAuthorVar = "YourName";
  $secretpassword = "YourPassword";
  $numEntries = 5; //Number of blog entries to display on each page

function displayEntries($author, $limitTotal = "", $limitBegin = "0")
{
   global $database;
   $connection = db_connect($database);

   if( IsSet($limitTotal) && $limitTotal != "" ){
      $limit = "LIMIT $limitBegin, $limitTotal";
   }
   $query  = "SELECT title, date, blogEntry, entryID FROM $author ORDER BY date DESC, entryID DESC $limit";
   $result = db_query($query);

   while( $row = db_fetch_row($result) )
   {
       $row[0] = stripslashes($row[0]);
       $row[2] = stripslashes($row[2]);

       print "      <div class=\"blogentry\" id=\"entry$row[3]\">\n";
       print "        <div class=\"entrytitle\">$row[0]</div>\n";
       print "        <div class=\"blogcomment\">$row[2]</div>\n";
       print "        <div class=\"entrydate\">Posted by $author on $row[1]</div>\n";
       print "      </div>\n";
       print "      <br/>\n";
   }
   db_close();

}

function printLinks($author,$numEntriesDisplayed,$skip){
   global $database;
   $connection = db_connect($database);

   $query  = "SELECT count(entryID) FROM $author";
   $result = db_query($query);
   $row = db_fetch_row($result);
   $totalEntries = $row[0];
   $counter = $totalEntries-$numEntriesDisplayed-$skip;
   $numLoops = 0;
   $PHP_SELF = $_SERVER['PHP_SELF'];

   print "    <h3>Archive ($totalEntries total entries)</h3>\n";
   print "    <div class=\"blogarchivelinks\">\n";
   $entryDate = getDateForEntryNumber($author, $totalEntries);
   print "        <a class=\"blogarchivelink\" href=\"$PHP_SELF?skip=0\">$entryDate</a><br/>\n";
   while( $counter > 0 && $numLoops < 10)
   {
      printLink($author, $counter, $totalEntries - $counter); 
      $counter = $counter - $numEntriesDisplayed;
      $numLoops = $numLoops + 1;
   }

   /* Print links to older archives */

   if( $totalEntries > (25+$skip) && ($numLoops * $numEntriesDisplayed) < (25 + $skip))
      printLink($author, $totalEntries - 25 - $skip, 25 + $skip);
   if( $totalEntries > (50+$skip) && ($numLoops * $numEntriesDisplayed) < (50 + $skip))
      printLink($author, $totalEntries - 50 - $skip, 50 + $skip);
   if( $totalEntries > (100+$skip) && ($numLoops * $numEntriesDisplayed) < (100 + $skip))
      printLink($author, $totalEntries - 100 - $skip, 100 + $skip);
   if( $totalEntries > (200+$skip) && ($numLoops * $numEntriesDisplayed) < (200 + $skip))
      printLink($author, $totalEntries - 200 - $skip, 200 + $skip);

   print "    </div>\n";
   db_close();
}

function printLink($author, $counter, $entryskip){
      $entryDate = getDateForEntryNumber($author, $counter);
      //$entryskip = $totalEntries - $counter;
      print "        <a class=\"blogarchivelink\" href=\"$PHP_SELF?skip=$entryskip\">$entryDate</a><br/>\n";
}

function getDateForEntryNumber($author, $counter){
      $counter = $counter-1;
      $query2 = "SELECT date FROM $author LIMIT $counter, 1";
      $result2 = db_query($query2);
      $row2 = db_fetch_row($result2);
      return $row2[0];
}

?>
Return current item: BlogHelper