Mind blowing SEO improving and Google rank increasing Signature Rotator SEO Tool.

Thread: 

how to show number of threads & post of a forum

Ads
lion Offline referral

Posts: 122
Joined: May 2014
Reputation: 0

#1
Member
Hello
I want to know how can I show number of posts & threads of a forum everywhere I want ?

Heart
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#2
Support Team
Can't be done without a plugin.
lion Offline referral

Posts: 122
Joined: May 2014
Reputation: 0

#3
Member
Would you make a plugin for it ?
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#4
Support Team
Please tell me a bit more about what you need? What do you mean by "number of posts & threads"? Like 12345678901 Where do you wan to show this value?
lion Offline referral

Posts: 122
Joined: May 2014
Reputation: 0

#5
Member
for example there is 15 posts & 5 threads in a forum
I want to show 15 & 5 everywhere I want of my own forum
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#6
Support Team
It's easy to fetch the amount of posts and threads from the forum but to show it everywhere you want is kind of difficult.

In order to show it in X, X and X locations will require to create 3 different hooks.

There is a way to show it globally across the entire board by putting in in the header or footer.
These posts should give you an idea Fetch threads/posts mybb or Fetch posts from the forum
lion Offline referral

Posts: 122
Joined: May 2014
Reputation: 0

#7
Member
Thanks Marcus

I used this query :
Code:
    $query1 = $db->simple_select('posts', 'COUNT(pid) AS count1');

how can I make it to fetch amount of posts of my forum
where should I put FID variable ?
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#8
Support Team
Lets say I want to know how many threads and replies/posts there are in the forum fid143

PHP Code:
// Fetch replies and count them
$timesearchposts 143// This is forum FID value
    
$query $db->query("
            SELECT p.pid, p.fid, COUNT(*) AS poststoday
            FROM "
.TABLE_PREFIX."posts p
            WHERE p.fid = 
$timesearchposts
        "
);

    while (
$posts $db->fetch_array($query)) {
        echo(
"<div>Posts in the forum <strong>fid{$timesearchposts}</strong> - {$posts['poststoday']}</div><br/>");
    }
    
// Fetch threads and count them
    
$timesearchthreads 143// This is forum FID value
    
$query2 $db->query("
            SELECT t.tid, t.fid, COUNT(*) AS poststoday
            FROM "
.TABLE_PREFIX."threads t
            WHERE t.fid = 
$timesearchthreads
        "
);

    while (
$threads $db->fetch_array($query2)) {
        echo(
"<div>Threads in the forum <strong>fid{$timesearchthreads}</strong> - {$threads['poststoday']}</div><br/>");
    } 
lion Offline referral

Posts: 122
Joined: May 2014
Reputation: 0

#9
Member
Thanks
but it couldn't count

maybe I had made mistake , would you give me the plugin ?
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#10
Support Team
Where do you want to show the message?
lion Offline referral

Posts: 122
Joined: May 2014
Reputation: 0

#11
Member
Index Template
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#12
Support Team
PHP Code:
<?php

if(!defined("IN_MYBB"))
{
    die(
"Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("index_start""poststhreadscount");

function 
poststhreadscount_info()
{    
    return array(
                
"name" => "Posts Threads Counter",
                
"description" => "Polls the number of posts and threads from the forum of your choice ",
                
"website" => "http://letsforum.com/Thread-how-to-show-number-of-threads-post-of-a-forum",
                
"author" => "Victor Dub",
                
"authorsite" => "http://letsforum.com",
                
"version" => "1",
                
"compatibility" => "16*"
            
);
}

function 
poststhreadscount()
{
    global 
$mybb$poststhreadscounter$db;
    
  
// Fetch replies and count them
$timesearchposts 143// This is forum FID value
    
$query $db->query("
            SELECT p.pid, p.fid, COUNT(*) AS poststoday
            FROM "
.TABLE_PREFIX."posts p
            WHERE p.fid = 
$timesearchposts
        "
);

    while (
$posts $db->fetch_array($query)) {
        
$postscounter "<span>Posts in the forum <strong>fid{$timesearchposts}</strong> - {$posts['poststoday']}</span>";
    }
    
// Fetch threads and count them
    
$timesearchthreads 143// This is forum FID value
    
$query2 $db->query("
            SELECT t.tid, t.fid, COUNT(*) AS poststoday
            FROM "
.TABLE_PREFIX."threads t
            WHERE t.fid = 
$timesearchthreads
        "
);

    while (
$threads $db->fetch_array($query2)) {
        
$threadscounter "<span>Threads in the forum <strong>fid{$timesearchthreads}</strong> - {$threads['poststoday']}</span>";
    } 

        
$poststhreadscounter "<div>{$postscounter}{$threadscounter}</div>";

}
?>

1. Save as poststhreadscount.php
2. Add {$poststhreadscounter} somewhere in the index template.
3. Replace $timesearchthreads = 143; with your forum FID
4. Customize texts





User(s) browsing this thread: 1 Guest(s)