View Full Version : Put phrase in navbar link title
thedukeboard
08-02-2012, 05:34 PM
Hi, I'd really appreciate someone helping me know how to put a phrase in the link title of a navbar/submenu link. Every time I do it the phrase ({vb:raw num_chatting}) just appears as plain text instead of showing up as I'd like it.
I'm using 4.2
Thanks in advance.
You can't put in anything other than text. If you wanted to provide translations what you could do is find the phrases that are created for each tab or link then enter the translations there.
But it looks like what you want is for the text to be "dynamic" so you can have it display the current number of people in chat? To do that you could create a plugin using hook build_navigation_data and override the text for a tab or link, like:
$identity = 'link_abc5_abc'; // change this to "Identity" of tab or link
$num_chatting = 5; // obviously you'll need to set this
$navdata[$identity]['text'] = $num_chatting;
// or if you want to use a phrase, do something like this instead:
$navdata[$identity]['text'] = construct_phrase($vbphrase['num_chatting'], $num_chatting);
thedukeboard
08-02-2012, 07:30 PM
Thanks for the reply. I tried making that plugin but it just made the link disappear.
Here is the plugin I was originally using:
$result = mysql_query("SELECT * FROM ajax_chat_online");
$num_chatting = mysql_num_rows($result);
vB_Template::preRegister('navbar',array('num_chatt ing' => $num_chatting));
vB_Template::preRegister('FORUMHOME',array('num_ch atting' => $num_chatting));
Then adding this link in to the navbar manually:
<li><a href="/chat/">Chat ({vb:raw num_chatting})</a></li>
It wouldn't position itself properly in the submenu like I'd like but it did display the correct amount of users chatting as I want it. Any idea how to amend that plugin or where I can manually add the link in 4.2?
Thanks again for taking the time.
Hmm...if your link disappeared then you must have been on the right track. I'd have to see exactly what code you used (did you maybe leave the last line there without actually having created a phrase?).
Sorry, I don't know how you'd go about adding it manually.
thedukeboard
08-02-2012, 10:22 PM
$identity = 'link_mzg2_354'; // change this to "Identity" of tab or link
$num_chatting = 5; // obviously you'll need to set this
Link displays but nothing showing users in chat.
Ideally I'd like it to appear as Chat (1) [1 being the number of users currently in], pulling the ajax data I posted above.
I'm new to this.
OK, maybe your plugin code could be this (using hook build_navigation_data - and you can disable the other plugin):
if (is_array($navdata['link_mzg2_354']))
{
$result = mysql_query("SELECT * FROM ajax_chat_online");
$num_chatting = mysql_num_rows($result);
$navdata['link_mzg2_354']['text'] = "Chat ($num_chatting)";
}
thedukeboard
08-02-2012, 10:43 PM
It worked! Thanks sooooo much.
vBNinja
04-07-2013, 07:47 PM
OK, maybe your plugin code could be this (using hook build_navigation_data - and you can disable the other plugin):
if (is_array($navdata['link_mzg2_354']))
{
$result = mysql_query("SELECT * FROM ajax_chat_online");
$num_chatting = mysql_num_rows($result);
$navdata['link_mzg2_354']['text'] = "Chat ($num_chatting)";
}
I'm trying to do the same thing but im using 4.1.10 and it doesn't have that hook, is there another way I can do it?
Thanks! :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.