MyBB Community Forums

Full Version: Pulling fid & tid into a script - how?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there,

I'm new to MyBB and am in the process of setting up a forum. I must say I am extremely impressed at first pass.

I am trying to pull the fid (Forum ID) and tid (Thread ID) variables into a script I'm running in a template. So far I have called them through as such:

fid={$mybb->input['fid']};tid={$mybb->input['tid']}

Beautiful stuff happens with this. The forum ID shows on the relevant forum page and the thread ID is populated with no probs on a thread page. The relevant fid that pertains to a thread however does not show on thread pages.

Any idea how I can make that happen? I also need a non-dynamic solution - i.e. the same code needs to go site-wide.

Thanks very much.

Greg
Hi,

Try using either of the following for various parts of MyBB:
Forum ID
{$forum['fid']}
{$fid}
{$thread['fid']}
Thread ID
{$thread['tid']}
{$tid}

Note that not all parts of your forum will fall under a forum/thread, so it won't make sense to have a TID/FID for them Toungue
Hi there,

Thanks for your reply. I am aware that TID will only be relevant on a thread. None of those variables you stated worked.

My main problem is getting the FID to populate on a thread page. I've managed to get FID to populate by passing it into the string in the URL with the existing variable I'm using fid={$mybb->input['fid']}.

Is it aggro to make any reference to a thread contain fid in the URL string when a user visits it?
Could you please post your template, and where it's evaluated? If it's in something like header, which is eval'd before the showthread script kicks in, then the variables I posted won't work.

I would suggest against putting the FID in the URL because, a) a user could just pass a junk value to FID, and b) potential inconsistencies.
Hi,

I can tell you that I am putting this in the header section. Here is some of my header template:

<div id="container">
		<div id="header"><a name="top" id="top"></a>
<div id="mast">
<div class="topbox">

<!-- BEGIN CODE /-->

<script language="JavaScript" type="text/javascript">
ord=Math.random()*10000000000000000;
document.write('<script language="JavaScript" src="http://xxx.xxxxxx.xxx/xxx/xxxxx/forum;fid={$mybb->input['fid']};tid={$mybb->input['tid']};ord=' + ord + '?" type="text/javascript"></scr' + 'ipt>');
</script>

<!-- END CODE /-->

  </div>
  <div class="headbox">

<!-- BEGIN CODE /-->

<script language="JavaScript" type="text/javascript">
document.write('<script language="JavaScript" src="http://xxx.xxxxxx.xxx/xxx/xxxxx/forum;fid={$mybb->input['fid']};tid={$mybb->input['tid']};ord=' + ord + '?" type="text/javascript"></scr' + 'ipt>');
</script>

<!-- END CODE /-->

 </div>
  <div class="headedit">

{$welcomeblock}
  </div>

  <div id="logo"><a href="{$mybb->settings['bburl']}/index.php"><img src="{$theme['logo']}" alt="{$mybb->settings['bbname']}" /></a></div>

  <div class="searchbar">
<p>

<form method="post" action="{$mybb->settings['bburl']}/search.php">
<input type="hidden" name="action" value="do_search" />
<input type="hidden" name="postthread" value="1" />
<input type="hidden" name="forums" value="all" />
<input type="hidden" name="showresults" value="threads" />
<input type="text" class="searchbox" name="keywords" onfocus="this.value = ''" value="Search Forums" />
<input  name="imageField" type="image" class="searchbutton"  src="http://www.xxxxxxxxxxx.xxxx/mast_search_but.gif" />
</form>

</p>
  </div>
  <div class="advancedsearch">
<a href="{$mybb->settings['bburl']}/search.php" class="off">Advanced Search</a>
<a href="http://www.xxxxxxxxxx.xxxxx/xxxxxxxxxxxxxx.xxx" target="_blank" class="off">Search</a>
  </div>
 </div>
<div id="topnav">
    <ul id="menu">
<li>
<a href="http://www.xxxxxxxxxxxxxxxx.xxxx">Home</a></li>
<li>
<a href="http://forum.xxxxxxxxx.xxxxxx/forums/">Forum Home</a>
</li>
<li>
<a href="{$mybb->settings['bburl']}/search.php">{$lang->toplinks_search}</a>
</li>
<li>
<a href="{$mybb->settings['bburl']}/memberlist.php">{$lang->toplinks_memberlist}</a>
</li>
<li>
<a href="{$mybb->settings['bburl']}/calendar.php">{$lang->toplinks_calendar}</a>
</li>
<li>
<a href="http://www.xxxxxxxxxxxxxxx.xxx" target="_blank">Jobs</a>
</li>
<li class="last">
<a href="{$mybb->settings['bburl']}/misc.php?action=help">{$lang->toplinks_help}</a></li>
</ul>

</div>

		</div>
		<hr class="hidden" />
		<br class="clear" />
		<div id="content">
			{$bannedwarning}
			{$bbclosedwarning}
			{$unreadreports}
			<navigation>
			<br class="clear" />
It looks like you're trying to retrieve a random Javascript file?

I'd recommend against putting it in the header template. As stated, you can't really get get the IDs from there, and also, for parts of the forum which don't fall under a forum category, you're just going to have 0's in the TID/FID.

I'd place your code in the forumdisplay and showthread templates, and, if you want to, newreply, editpost, and newthread, instead of header
It's not a *random* JavaScript file as it's supposed to be there Big Grin. I'm wishing to use FID & TID as variables in my JavaScript. I'm aware that on a non-thread page nothing is returned into TID and that is not a problem. Unfortunately the script must sit in the header as it makes an image show. Can I pass the FID value back up to header from somewhere else? Or is there a script I can run in the header to make FID work?

Thanks for your help so far.
In global.php, find:
eval("\$header = \"".$templates->get("header")."\";");
Before that, add:
if($mybb->input['tid'] && !$mybb->input['fid'])
{
    $t_temp = get_thread($mybb->input['tid']);
    $mybb->input['fid'] = $t_temp['fid'];
}
DENNIS!

You are the man. Worked like a charm. Absolutely brilliant. Thanks very very much.