PDA

View Full Version : How To Show Thread And Post Counts For Forums Even When User Doesn't Have Access



Jake Bunce
Tue 24th Aug '04, 6:35pm
Many forum admins want guests (or other users who don't have access to a private forum) to see that there are threads and posts in that forum. Under the current system, if a user doesn't have access to a forum then it will show 0 threads and 0 posts in the forum listing. You can use this method to show the true counts regardless of forum permissions.

Note, If you have a ton of forums then this code can add a lot of processing time to your forumhome and forumdisplay pages.

Go to your:

Admin CP -> Styles & Templates -> Style Manager -> « » -> PHP Include Code Templates -> phpinclude_start

Add this code:



// IF FORUMHOME OR FORUMDISPLAY PAGE
if (THIS_SCRIPT == 'index' OR THIS_SCRIPT == 'forumdisplay')
{
// GET FORUM COUNTERS
$forumcounts= $DB_site->query("SELECT forumid, replycount, threadcount
FROM " . TABLE_PREFIX . "forum
");

// SET VALUES
while ($forumcount = $DB_site->fetch_array($forumcounts))
{
$forumreply[$forumcount[forumid]] = $forumcount[replycount];
$forumthread[$forumcount[forumid]] = $forumcount[threadcount];
}
}


Then go to your:

Admin CP -> Styles & Templates -> Style Manager -> « » -> Forum Home Templates -> forumhome_forumbit_level1_post

Replace the red code...



<td class="alt2" nowrap="nowrap">$forum[lastpostinfo]</td>
<td class="alt1">$forum[threadcount]</td>
<td class="alt2">$forum[replycount]</td>
<if condition="$vboptions['showmoderatorcolumn']">
<td class="alt1"><div class="smallfont">$forum[moderators]&nbsp;</div></td>
</if>


...with the blue code:



<td class="alt2" nowrap="nowrap">$forum[lastpostinfo]</td>
<td class="alt1">{$GLOBALS[forumthread][$forum[forumid]]}</td>
<td class="alt2">{$GLOBALS[forumreply][$forum[forumid]]}</td>
<if condition="$vboptions['showmoderatorcolumn']">
<td class="alt1"><div class="smallfont">$forum[moderators]&nbsp;</div></td>
</if>


Make a similar change to the forumhome_forumbit_level2_post template.

Jake Bunce
Sat 6th Nov '04, 3:31pm
In addition, to complete the effect, you can add a conditional to replace "Never" in the Last Post field with "Private":

Admin CP -> Styles & Templates -> Style Manager -> « » -> Forum Home Templates -> forumhome_forumbit_level2_post

Add the red code:



<tr align="center">
<td class="alt2"><img src="$stylevar[imgdir_statusicon]/forum_$forum[statusicon].gif" alt="" border="0" /></td>
<td class="alt1Active" align="$stylevar[left]" id="f$forum[forumid]">
<div>
<a href="forumdisplay.php?$session[sessionurl]f=$forum[forumid]"><strong>$forum[title]</strong></a>
<if condition="$show['browsers']"><span class="smallfont">(<phrase 1="$forum[browsers]">$vbphrase[x_viewing]</phrase>)</span></if>
</div>
<if condition="$show['forumdescription']"><div class="smallfont">$forum[description]</div></if>
<if condition="$show['forumsubscription']"><div class="smallfont"><strong><a href="subscription.php?$session[sessionurl]do=removesubscription&amp;f=$forum[forumid]">$vbphrase[unsubscribe_from_this_forum]</a></strong></div></if>
<if condition="$show['subforums']"><div class="smallfont" style="margin-top:$stylevar[cellpadding]px"><strong>$vbphrase[subforums]</strong>: $forum[subforums]</div></if>
</td>
<td class="alt2" nowrap="nowrap"><if condition="$forum[lastpostinfo] == 'Never'">Private<else />$forum[lastpostinfo]</if></td>
<td class="alt1">$forum[threadcount]</td>
<td class="alt2">$forum[replycount]</td>
<if condition="$vboptions['showmoderatorcolumn']">
<td class="alt1"><div class="smallfont">$forum[moderators]&nbsp;</div></td>
</if>
</tr>
$childforumbits


Make a similar change to the forumhome_forumbit_level1_post template.

Jake Bunce
Fri 3rd Dec '04, 1:31pm
One shortcoming of this modification is that it doesn't include posts / threads from child forums in the counts. For example, if your forums are like this:

Category 1
- Forum1
- - forum1a
- - forum1b
- Forum2

Then the post and thread counts for Forum1 will only include posts in Forum1, and not those in forum1a and forum1b.

So if you have a forum tree with postable forums nested within postable forums, then the reported post and thread counts with this modification will be wrong.

If this is your situation, then a file hack would be more appropriate than this template mod. For help with a hack you should post on www.vbulletin.org.