Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Plugin: bb-Topic-Views


_ck_
Participant

@_ck_

I’ve now come up with an extremely easy/fast way to grab and display the views per forum in the forum list on the front page (or forums with sub-forums.

Here’s the plugin:

function forums_views_append($forums) {
global $bbdb; $sum_meta_value="SUM(meta_value)";
$forums_views = $bbdb->get_results(" SELECT $sum_meta_value,forum_id FROM $bbdb->topicmeta LEFT JOIN $bbdb->topics ON $bbdb->topicmeta.topic_id = $bbdb->topics.topic_id WHERE $bbdb->topicmeta.meta_key='views' GROUP BY $bbdb->topics.forum_id");
foreach ($forums_views as $forum_views) {$forums[$forum_views->forum_id]->views=$forum_views->$sum_meta_value; }
return $forums;
}
add_filter('get_forums','forums_views_append');

To display the views, edit your front-page.php template and insert a views header and views column like so:

<th><?php _e('Views'); ?></th>
<th><?php _e('Topics'); ?></th>
<th><?php _e('Posts'); ?></th>

.

<td><?php echo $forum->views; ?></td>
<td><?php forum_topics(); ?></td>
<td><?php forum_posts(); ?></td>

Since there is no clean way to store forum meta data right now in bbpress (apparently an oversight) this will run on every time the forums list is displayed. Maybe not such a good idea for very busy forums, even though it’s a single mysql query (nifty eh?).

Eventually I’ll figure out a nice way to store this and only update upon new posts or new topics to reduce overhead (or a cron job perhaps).

Skip to toolbar