TinyPortal

Development => Support => Topic started by: guvenck on August 01, 2006, 01:51:43 PM

Title: Display boardnames of a category within a TP Block
Post by: guvenck on August 01, 2006, 01:51:43 PM
Hi, I need a block code that displays the boardnames from a category as links to the board in a TP block.
Can someone help me here?
Title: Re: Display boardnames of a category within a TP Block
Post by: Xarcell on August 01, 2006, 02:05:55 PM
I've been looking for the same thing.
Title: Re: Display boardnames of a category within a TP Block
Post by: guvenck on August 01, 2006, 02:13:42 PM
I could do it with external SQL queries in a phpblock, but perhaps there are easier to use functions within TP and/or SMF.
Title: Re: Display boardnames of a category within a TP Block
Post by: guvenck on August 01, 2006, 02:28:08 PM
Xarcell: I made a simple one-level list without caring about the permissions.
Put following in a phpblock:



$hostname = "localhost"; // MySQL server
$dbname = "mysqldbname"; // Your MySQL DBName
$dbusername = "mysqlusername"; // Your MySQL Username
$dbpass = "mysqlpassword"; // Your MySQL Password

$cat = 1; // Category ID you want the boards to be fetched

if (!isset($connection)) {
    $connection = mysql_connect($hostname, $dbusername, $dbpass) or die(mysql_error());
    mysql_select_db($dbname, $connection) or die(mysql_error());
}

$query = "SELECT ID_BOARD, name FROM smf_boards WHERE ID_CAT='$cat'";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result)) {
echo "<a href=\"index.php?board=$row[0].0\">$row[1]</a><br>";
}

Title: Re: Display boardnames of a category within a TP Block
Post by: JPDeni on August 01, 2006, 02:33:16 PM
SMF already connects to the database. You don't have to do it again. Here's the same thing, listing all of the boards and child boards in a category, in the order they appear on your forum:
global $scripturl;
$category = 2; // Change this to the number of the category you want

$query = db_query(
  "SELECT ID_BOARD, name
   FROM smf_boards
   WHERE ID_CAT = $category
   ORDER BY boardOrder", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($query))
{
  echo '<a href="' . $scripturl . '?board=' . $row['ID_BOARD'] . '">' . $row['name'] . '</a><br />';
}


It doesn't check permissions, either, so you would only want to use this when your board was accessible to everyone.
Title: Re: Display boardnames of a category within a TP Block
Post by: guvenck on August 01, 2006, 03:32:15 PM
See, that's what I'm talking about :)
Title: Re: Display boardnames of a category within a TP Block
Post by: bloc on August 01, 2006, 05:38:55 PM
Serves as a good way to let people see whats inside - a sneak preview even if the boards are restricted.
Title: Re: Display boardnames of a category within a TP Block
Post by: guvenck on August 01, 2006, 06:36:42 PM
Also, it attracts people to visit the forums. In my case, I run a TV Series site and have a single board dedicated to each title. Have more than one hundred boards this way, imagine what a visitor would feel like when he/she sees the huge list at the right side. This could be a better way to take him to the Forums.