Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding Topic View Count to forums


  • fishbowl81
    Participant

    @fishbowl81

    I have implemented a very simple view counter, by adding in a few lines of code into the bbpress-live class.

    // update meta

    $value = get_site_option($bp.”_topic_views_”.$topic);

    add_site_option( $bp.”_topic_views_”.$topic, $value+1);

    I added those into the get posts method, which I discovered after finalizing my code that it increments every time the forum page is show. With a bit more tweaking I will have it finalized.

    Then I created a simple function to display the view count:

    function bp_the_topic_view_count($topic_id = false, $echo = true) {

    global $action_variables;

    global $bp;

    global $forum_template;

    if($topic_id == false)

    $views = get_site_option($bp.”_topic_views_”.$forum_template->topic->topic_id);

    else

    $views = get_site_option($bp.”_topic_views_”.$topic_id);

    if(!$views)

    return false;

    if($echo)

    {

    if($views == 1)

    echo apply_filters( ‘bp_the_topic_post_count’, $views.” view” );

    else

    echo apply_filters( ‘bp_the_topic_post_count’, $views.” views” );

    }else

    {

    if($views == 1)

    return apply_filters( ‘bp_the_topic_post_count’, $views.” view” );

    else

    return apply_filters( ‘bp_the_topic_post_count’, $views.” views” );

    }

    }

    Curious what people think, you can see the results in action here:

    http://gorgeousgamers.com/beta/forums/chat/1/general-discussions

    Thanks,

    Brad

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding Topic View Count to forums’ is closed to new replies.
Skip to toolbar