Search

bbPress Showcase » bbPress Chat

How did you get the total view counts on the forum list?

RSS
  1. ChadTheDJ
    User has not uploaded an avatar

    junior member
    Joined: Feb '11
    Posts: 6

    offline

    I am trying to add that to mine and curious where can I find the code?

    Thanks!

    Also is there something I can find where you can list the topic other in the table list?

    Posted 1 year ago #
  2. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 908

    offline

    I include that functionality in the My Views plugin but here is a newer version of the code that calculates it only once every 10 minutes and saves the result to reduce the load.

    Once you install the plugin, you just add a column to the forum table like this:

    <td class="num"><?php echo bb_number_format_i18n($GLOBALS['forum']->views); ?></td>
    <?php
    /*
    Plugin Name: Forum Views
    Author: _ck_
    Author URI: http://bbShowcase.org
    */
    add_filter('get_forums','forums_views_append');
    
    function forums_views_append($forums) {
    	if (!is_front() && !is_forum()) {return $forums;}
    	global $bbdb, $forums_views;
    	if (empty($forums_views)) {$forums_views=bb_get_option('forums_views');}
    	if (empty($forums_views) || floor($forums_views[0]/600)!=floor(time()/600)) {
    		if (empty($forums_views)) {$old_sum=0;} else {$old_sum=array_sum($forums_views);}
    		if (defined('BACKPRESS_PATH')) {
    			$query="SELECT forum_id, SUM(meta_value) AS sum_meta_value
    			FROM $bbdb->meta LEFT JOIN $bbdb->topics ON $bbdb->meta.object_id = $bbdb->topics.topic_id
    			WHERE $bbdb->topics.topic_status=0 AND $bbdb->meta.meta_key='views'  AND $bbdb->meta.object_type='bb_topic'
    			GROUP BY $bbdb->topics.forum_id";
    		} else {
    			$query="SELECT forum_id, SUM(meta_value) AS sum_meta_value
    			FROM $bbdb->topicmeta LEFT JOIN $bbdb->topics ON $bbdb->topicmeta.topic_id = $bbdb->topics.topic_id
    			WHERE $bbdb->topics.topic_status=0 AND $bbdb->topicmeta.meta_key='views'
    			GROUP BY $bbdb->topics.forum_id";
    		}
    		$results = $bbdb->get_results($query);
    		foreach ($results as $result) {$forums_views[$result->forum_id]=$result->sum_meta_value;}
    		$new_sum=array_sum($forums_views);
    		// if ($old_sum!=$new_sum) {
    			$forums_views[0]=time();
    			if ($old_sum==0) {bb_update_option('forums_views',$forums_views);}
    			else {
    				$value=addslashes(serialize($forums_views));
    				if (defined('BACKPRESS_PATH')) {
    					$query="UPDATE $bbdb->meta SET meta_value='$value' WHERE object_id='0' AND object_type='bb_option' AND meta_key='forums_views'  LIMIT 1";
    				} else {
    					$query="UPDATE $bbdb->topicmeta SET meta_value='$value' WHERE topic_id=0 AND meta_key='forums_views'  LIMIT 1";
    				}
    				@$bbdb->query($query);
    			}
    		// }
    	}
    	foreach ($forums as $id=>$forum) {if (!empty($forums_views[$id])) {$forums[$id]->views=$forums_views[$id];} else {$forums[$id]->views=0;}}
    return $forums;
    }
    Posted 1 year ago #
  3. ChadTheDJ
    User has not uploaded an avatar

    junior member
    Joined: Feb '11
    Posts: 6

    offline

    Thanks man! Do you have any plugin to see the forum posts author?

    Posted 1 year ago #
  4. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 908

    offline

    Yah, see this http://bbpress.org/plugins/topic/forum-last-poster/

    This is a demo of the bbPress Signatures plugin!
    If you use my plugins, please considering donating to help continue their development.
    Posted 1 year ago #
  5. ChadTheDJ
    User has not uploaded an avatar

    junior member
    Joined: Feb '11
    Posts: 6

    offline

    Thanks so much for your help and I did discover that last night. I love BBpress so far but been running into a few glitches. Like for some reason I lost my stickies and the forum freshness displays times for the last post. I think I might be using the wrong function but I can figure it out.

    If I need more of your help, I will be giving you a donation so I can get my system up and running

    Oh some of my members are asking if do you have a version of Post Count Plus with more Custom Titles?

    Here is what I got so far: http://www.mcserverreview.com/forum
    (still building the CSS and PHP)

    Posted 1 year ago #
  6. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 908

    offline

    I would advise you asking the rest of your questions on bbpress.org as my time is extremely limited these days.

    Donations aren't payments for services, they would be for all of my plugins you are already using I'm not actually for hire.

    Posted 1 year ago #
  7. ChadTheDJ
    User has not uploaded an avatar

    junior member
    Joined: Feb '11
    Posts: 6

    offline

    OK. Thanks for the help then.

    Posted 1 year ago #
  8. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 908

    offline

    By the way, your query count for every page is entirely too high, almost twice what it should be, making things slow.

    Because you are using 1.0 this is more difficult to fix.

    But you can find some of my tips and tricks on bbpress.org

    http://bbpress.org/forums/topic/heres-how-to-fix-some-of-the-10-query-performance-regression

    Posted 1 year ago #

RSS feed for this topic

Post a reply to “How did you get the total view counts on the forum list?”

You must log in to post.

keep _ck_ coding >> donate $5 <<     Theme Switcher:
40 users online from in the past 30 minutes. 15 bots 25 guests
3,643 views today 8,638 yesterday 16,043 peak. Most at once 47 today 60 yesterday 131 peak. Visited today: qamilon, pandoracam, lvgalliera
2,288 posts in 394 topics over 66 months by 430 of 2,165 members. Latest: qwe12345100, Janvelden, watchessaleus