Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding Topic View Count to forums

  • Avatar of Fishbowl81
    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)
  • Avatar of Nicola Greco
    nicolagreco
    Participant

    @nicolagreco

    you should update your script with the new $bp structure

    $bp should be $bp->current_component

    Avatar of kriskl
    kriskl
    Participant

    @kriskl

    Could anyone update this? or add this to a plugin?

    please

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.