Jump to content

Forum Main with Categories


Solar

Recommended Posts

Hello! I've got exactly what I've wanted in my previous topic so I have decided to make a new topic for some help.

 

General

General Discussion

Description here

 

Entertainment Discussion

Description here

 

Gaming

Console Discussion

Description here

 

Handheld Discussion

Description here

 

And a database like this;

id title description parent

1 General description here 0

2 Gaming description here 0

3 General Discussion description here 1

4 Entertainment Discussion description here 1

5 Console Discussion description here 2

6 Handheld Discussion description here 2

 

<?php
function generate_forums($parent)
{
$has_childs = false;

global $forums_array;        

foreach($forums_array as $key => $value)        
{
if ($value['parent'] == $parent)
{
if ($has_childs === true)
	{
	$has_childs = false;
	}
	echo '<a href="/category/' . $value['title'] . '/">' . $value['title'] . '</a><br>' . $value['description'] . '';        
	generate_forums($key);        
	echo '<br>';
	}
} 
}
generate_forums(0);
?>

 

The code works wonders. But it is hard to customize template wise.

 

$ID#1 $title = General

I would start off with <table>

I need to have the Categories that Parent = ( 0 ) to have a HTML <tr>

I also need the Categories with Parent = ( Value ) to have a HTML <td>

Then the tags would be closed off before $ID#2 $title = Gaming's template would start again.

 

I keep trying to scramble the coding around and can't seem to find that probably "simple" touch.

Thanks in Advanced.

Link to comment
https://forums.phpfreaks.com/topic/237462-forum-main-with-categories/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.