Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: “My Threads” – User Specific Views


_ck_
Participant

@_ck_

I haven’t seen them (doesn’t mean it doesnt exist) but I’ve figured out the framework on how to build and attach a view if you’d like to copy my homework :D

This is the code I whipped up for “most-views” and “least-views” (which requires the view count plugin to be installed (and inserting the views column in view.php)

function most_views_views( $views ) {
global $views;
$views['most-views'] = 'Topics with the most views';
return $views;
}
add_filter('bb_views', 'most_views_views');

function least_views_views( $views ) {
global $views;
$views['least-views'] = 'Topics with the least views';
return $views;
}
add_filter('bb_views', 'least_views_views');

function most_views( $view ) {
global $bbdb, $topics, $view_count;
if ($view=='most-views') {$sort="DESC";}
if ($view=='least-views') {$sort="ASC";}
if ($view=='least-views' || $view=='most-views') {
$limit = bb_get_option('page_topics');
$where = apply_filters('get_latest_topics_where','');
$most_views = $bbdb->get_results("SELECT topic_id FROM $bbdb->topicmeta WHERE meta_key='views' ORDER BY cast(meta_value as UNSIGNED) $sort LIMIT $limit");
foreach (array_keys($most_views) as $i) {$trans[$most_views[$i]->topic_id] =& $most_views[$i];} $ids = join(',', array_keys($trans));
$topics ="SELECT * FROM $bbdb->topics WHERE topic_status=0 AND topic_id IN ($ids) $where ORDER BY FIELD(topic_id, $ids)";
$topics = $bbdb->get_results($topics);
$view_count = count($topics);
$topics = bb_append_meta( $topics, 'topic' );
}
else {do_action( 'bb_custom_view', $view );}
}
add_action( 'bb_custom_view', 'most_views' );

As you can see a new view requires both 1. an action 2. a filter

Easy once you’ve seen it, but try figuring it out from scratch!

This bit adds the title to view pages (missing by default in bbpress)

function bb_get_view_title($title) {
if (is_view()) {$title = get_view_name(). ' « ' . bb_get_option( 'name' ); }
return $title;
}
add_filter( 'bb_get_title', 'bb_get_view_title' );

Skip to toolbar