MyBB Community Forums

Full Version: Get {$forum['fid']} at the index templates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi,

I know that {$forum['fid']} only define in forumbit and forumdisplay templates.

But now I want to use that variable in the index templates.


I checked index.php file and found that inc/function_forumlist.php already called.

But why the $forum['fid'] can't be called ?

Please teach me how to use it.

Thanks, I'm new to MyBB Toungue
Try this:

	// Get the FIDs!.
	$query = $db->query("
		SELECT f.*, fr.dateline AS lastread
		FROM ".TABLE_PREFIX."forums f
		WHERE f.active != 0
		ORDER BY pid, disporder
	");

Use a loop to get them all, say:

while($forum = $db->fetch_array($query))
{
     $newfids = $forum['fid'];
}
Wouldn't that reassign $newfids every time the loop, well, loops?

    // Get the FIDs!.
    $query = $db->query("
        SELECT fid
        FROM ".TABLE_PREFIX."forums
        WHERE active != 0
        ORDER BY fid
    ");

$result = $db->fetch_array($query);
foreach($result as $value)
{
$forum_fid[$value] = $value;
}
//$forum['fid1'] $forum['fid2'] etc.
Not Tested!

Why would you need fid's on the index? AFAIK they don't reference anything unless you plan to pull threads from a forum, and even then you can hardcode the fid in.
@Seabody, thanks for correcting it Big Grin I am no good at SQL, so I didn't know what to put inside the loop to make it continue Big Grin

or maybe can we try this:
//Say i = 1 before loop starts Big Grin
$newfids[i] = $forum['fid'];
i++;

Considering $newfids as an Array?
To me, while() is useful for generating large tables of data, such as a threadlist. Could be wrong about your code though. Smile

echo "<table>";
while($result = mysql_fetch_assoc($query))
{
$threadlist .= "<tr><td>$result['subject']</td></tr>";
}
echo "<table>";

@OP thinking about it, how would you want this data? For instance, would you want $forum['fid1'] to have the value of forum 1's forum title? Storing '1' inside $forum['fid1'] is pretty useless, imho, and $forum['fid'] would only be useful storing the value of a GET array entry, like forumdisplay.php, as otherwise, it's impossible to tell what forum you're talking about.
@Cedric : Thanks for your help

@Seabody : Thanks you. I will try. I need the 'fid' in the index because I don't want to use collapse image to expand/collapse forum table. I'm working on a new theme, and I don't use any table anywhere (except the index, a little table)

//Edited :

I've used this simple jQuery to collapse forums.

<script type="text/javascript">jQuery.noConflict();jQuery("#cat_{$forum['fid']}").click(function() {jQuery(this).next().toggle();});</script>

And now this script has been put inside forumbit_depth1_cat and all of you know what was happened Wink This script will be loop for each category Big Grin

So I need the $fid, then put this script in the index template Big Grin
Oh, so it'd be a category? Try the forumbit_depth1_cat template, that would be the place you would (most likely) use it. Collapsing categories is only defined in the forumbits, because the index simply has {$threadlist} in it. Smile
(2013-03-28, 10:17 AM)Seabody Wrote: [ -> ]Oh, so it'd be a category? Try the forumbit_depth1_cat template, that would be the place you would (most likely) use it. Collapsing categories is only defined in the forumbits, because the index simply has {$threadlist} in it. Smile

Check my last edited post Rolleyes
Unless I'm misunderstanding you, what you ask isn't possible without a GET request. Individual forums are never requested on the index.

To clarify.
When you click on a thead, you want to collapse the tbody, basically emulating the current expcolimage functionality, except you are not using tables?
(2013-03-28, 10:22 AM)Seabody Wrote: [ -> ]Unless I'm misunderstanding you, what you ask isn't possible without a GET request. Individual forums are never requested on the index.

To clarify.
When you click on a thead, you want to collapse the tbody, basically emulating the current expcolimage functionality, except you are not using tables?

For example,

Here is my forumbit_depth1_cat

<a id="cat_{$forum['fid']}" href="javascript:;" class="forum-parent">{$forum['name']}</a>
<div class="child-forums" id="cat_{$forum['fid']}_e" style="{$expdisplay}">
<div class="forums-list">
{$sub_forums}
</div> <!-- /end forums-list -->
</div> <!-- /end child-forums -->
<span class="clear"></span>

I used jQuery to collapse it.

<script type="text/javascript">jQuery.noConflict();jQuery("#cat_{$forum['fid']}").click(function() {jQuery(this).next().toggle();});</script>


But the javscript code must be put inside forumbit_depth1_cat, so it will be called for each category I have.

Now I want to move the script to another place and only call it once.

That's it!

Hi.

If I use this code

// Get the FIDs!.
    $query = $db->query("
        SELECT fid
        FROM ".TABLE_PREFIX."forums
        WHERE active != 0
        ORDER BY fid
    ");

$result = $db->fetch_array($query);
foreach($result as $value)
{
$forum_fid[$value] = $value;
}
//$forum['fid1'] $forum['fid2'] etc. 

So what exactly templates variable I should use in the index templates?

{$forum['fid']} for every category?

Or {$forum['fid1']} for category 1 ?

I need a variable like MyBB {$forum['fid']} (for all forums)
Pages: 1 2