PDA

View Full Version : Adding module code to the navbar template


gopherhockey
11-05-2005, 11:52 PM
I want to add this code to my navbar so that the number of new posts is displayed below the private messages info. However, apparently the variables mean nothing in the navbar as shown, as they end up blank. I found this code inside the welcome block module.

In general if I wanted to take code out of a module and put it in a place like the header or navbar, what am I missing?


<if condition="THIS_SCRIPT == 'adv_index'">



<BR>
<a href="$vboptions[bburl]/search.php?$session[sessionurl]do=getnew">$vbphrase[new_posts]</a>: $newposts since your last visit.<br />

</if>

You can see the result of this code at www.morcmtb.net and you can see what I want my navbar to look like at www.morcmtb.org (You might see the login info rather than the stats... I still have to work on adding the events to the navbar on my new site as well...)

James Goddard
11-06-2005, 12:53 AM
Add a plugin to the "navbits" hook with the following:


$getnewposts = $db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "post WHERE dateline >= " . $vbulletin->userinfo['lastvisit']);
$newposts = vb_number_format($getnewposts['count']);

Our Sponsors
 

gopherhockey
11-06-2005, 07:51 PM
Thanks for the info. I kinda get where you are going here. This didn't work though - the variable $newposts isn't available in navbits doing it this way, and I get an error:

"Fatal error: Call to a member function on a non-object in /home/morcmtb/public_html/forums/includes/functions.php(1944) : eval()'d code on line 1"

When I click on various buttons to browse around the forums.

I saw a similar plugin on vbulletin.org that used a different hook area, maybe navbits just is the wrong place to register this?

Add a plugin to the "navbits" hook with the following:


$getnewposts = $db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "post WHERE dateline >= " . $vbulletin->userinfo['lastvisit']);
$newposts = vb_number_format($getnewposts['count']);

gopherhockey
11-06-2005, 08:49 PM
I found a similar module that uses the following code in the forumhome_start hook location (below). Strangely enough it works within the navbar on the forum home page, but it doesn't work in the same exact navbar on the vbadvanced home page.

Is there something I'm missing? It seems even the recent events hack I have works in the forum home index, but not the vbadvanced index page.

Don't hook variables work in vbadvanced templates?

I am desparately trying to get my navbar back to the way it looks on my 3.0 site www.morcmtb.org but with version 3.5 if vb, and the new 2.0 of vbadvanced.... it seems adding them to the portal output global variables doesn't fix this in all cases, especially with the variables newposts and newthreads.


if ($vbulletin->userinfo['userid'] != '0' AND (!$mod_options['portal_welcome_newposts']))
{
// Posts
$getnewposts = $db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "post WHERE visible = 1 AND dateline >= '{$vbulletin->userinfo['lastvisit']}'");
$newposts = number_format($getnewposts['count']);
// Threads
$getnewthreads = $db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "thread WHERE visible = 1 AND dateline >= '{$vbulletin->userinfo['lastvisit']}'");
$newthreads = number_format($getnewthreads['count']);
}

Our Sponsors
 

James Goddard
11-06-2005, 09:40 PM
"Fatal error: Call to a member function on a non-object in /home/morcmtb/public_html/forums/includes/functions.php(1944) : eval()'d code on line 1"


Navbits is the right place, but the database is not globalized in that function. Try this instead:


if ($vbulletin->userinfo['userid'] != '0' AND (!$mod_options['portal_welcome_newposts']))
{
global $db;
$getnewposts = $db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "post WHERE visible = 1 AND dateline >= '{$vbulletin->userinfo['lastvisit']}'");
$newposts = number_format($getnewposts['count']);
}