PDA

View Full Version : first post counted as reply in custom script


LifesGreatestGift
02-04-2013, 11:33 PM
I am working on building a classifieds section on my forum and the current code is counting the first post of a thread as a reply. is there a way around this? Here is my current code

$cats = array(18,19,20,21,22,23,24,25,26,27,28,29,30,31,32 ,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,4 9,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65, 66,67,68);

foreach ($cats AS $cat => $forumid) {
$t_count[$forumid] = array(
"forumid" => $forumid,
"forum_name" => $vbulletin->forumcache[$forumid]['title'],
"threadcount" => vb_number_format($vbulletin->forumcache[$forumid]['threadcount']),
"replycount" => vb_number_format($vbulletin->forumcache[$forumid]['replycount'])
);
}
foreach ($cats AS $cat) {
$total_count_thread += vb_number_format($vbulletin->forumcache[$cat]['threadcount']);
$total_count_reply += vb_number_format($vbulletin->forumcache[$cat]['replycount']);
}

$classifieds = array_merge($t_count);

if (is_member_of($vbulletin->userinfo, 6)) {
/* print_r($total_count_reply);
echo "<br />";
print_r($total_count_thread); */
}

vB_Template::preRegister('FORUMHOME',array('classi fieds' => $classifieds));
vB_Template::preRegister('FORUMHOME',array('total_ count_thread' => $total_count_thread));
vB_Template::preRegister('FORUMHOME',array('total_ count_reply' => $total_count_reply));

Here is where its rendered

https://www.thesecond.org/forum/#classifieds

if i make a "classified" aka thread, my "Listings" and "Replies" count is 1 when I'd like it to be Listings: 1 Replies: 0

Hope that makes sense.

Thanks in advance!

kh99
02-05-2013, 01:03 AM
It looks like the forum replycount is the number of posts including the first in each thread. But it seems like you should be able to get what you want by subtracting the threadcount from the replycount.

By the way, that's a very cool map you have there.

LifesGreatestGift
02-05-2013, 01:34 AM
Thanks! yeah, I cant remember, but does default vB4 in a brand new forum, when a new thread is made with its only post, does it show as 1 thread 1 reply, or 1 thread 0 replies ?

kh99
02-05-2013, 01:37 AM
I just made a new forum on my test site to check and it looks like the thread replycount field counts only replies after the first, but the forum replycount field (which it looks like you're using in the code you posted) counts every post including the first. So in my new forum (with one thread with only the first post), when I'm looking at it in the list of forums it shows 1 Thread and 1 Post, but when I list the threads in the forum, that thread shows 0 replies.

LifesGreatestGift
02-05-2013, 01:44 AM
Awesome. Thanks! The Threads minus Replies is a really good idea. I will implement that! Thanks again! And congrats on the mod position.

--------------- Added 1360032320 at 1360032320 ---------------

* Replies minus Threads ;)

--------------- Added 1360033677 at 1360033677 ---------------

Here is the new revised code for anyone wondering

$cats = array(18,19,20,21,22,23,24,25,26,27,28,29,30,31,32 ,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,4 9,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65, 66,67,68);

foreach ($cats AS $cat => $forumid) {
$t_count[$forumid] = array(
"forumid" => $forumid,
"forum_name" => $vbulletin->forumcache[$forumid]['title'],
"threadcount" => vb_number_format($vbulletin->forumcache[$forumid]['threadcount']),
"replycount" => vb_number_format(($vbulletin->forumcache[$forumid]['replycount']) - ($vbulletin->forumcache[$forumid]['threadcount']))
);
}
foreach ($cats AS $cat) {
$total_count_thread += vb_number_format($vbulletin->forumcache[$cat]['threadcount']);
$total_count_reply += vb_number_format(($vbulletin->forumcache[$cat]['replycount']) - ($vbulletin->forumcache[$cat]['threadcount']));
}

$classifieds = array_merge($t_count);

if (is_member_of($vbulletin->userinfo, 6)) {
/* print_r($total_count_reply);
echo "<br />";
print_r($total_count_thread); */
}

vB_Template::preRegister('FORUMHOME',array('classi fieds' => $classifieds));
vB_Template::preRegister('FORUMHOME',array('total_ count_thread' => $total_count_thread));
vB_Template::preRegister('FORUMHOME',array('total_ count_reply' => $total_count_reply));