• I made the following modification to bbp-topics.view.php to get an initial view count without having to view each post first.

    function btv_get_topic_view_count( $topic_id = 0 ) {
      $topic_id = bbp_get_topic_id( $topic_id );
    
      if ( empty( $topic_id ) )
        return 0;
    
      $views = (int) get_post_meta( $topic_id, '_btv_view_count', true );
    
      /**** begin modification ****/
      if ( $views == 0 ) {
        $views = bbp_get_topic_post_count( $topic_id );
    
        if ( $views > 1 )
          $views = $views + bbp_get_topic_reply_count_hidden( $topic_id );
    
        update_post_meta( $topic_id, '_btv_view_count', $views );
      }
      /**** end modification ****/
    
      return $views;
    }

    https://www.ads-software.com/extend/plugins/bbp-topic-views/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thanks anders, that has made a big difference to my forums, they are quite old and lots of zeros looked funny.

    Great tweak !

    Since you’ve obviously poked this code, I can see it on the topics page,but would be great to add it to an individual topic display.

    eg where it says
    “This topic contains 2 replies, has 2 voices, and was last updated by Matthew 1 week, 1 day ago.”
    Would be good to add …”and has been viewed 15 times.”

    Before I spend hours seeing if this is easy, can you supply a quick fix?

    Thread Starter Anders

    (@anme)

    I’m afraid I can’t help you with that.

    I’ve disabled the “This topic contains blah blah…” on my own site. It’s inserted by the call to bbp_single_topic_description() in content-single-topic.php.

    “I’m afraid I can’t help you with that.” – quite the opposite ! – this was exactly the time saving I needed to find and sort this and have sorted most of my problem out.

    But I need one more small bit of help if I may?

    I created a new function/action that is called by content-single-topic.php using the bbp_template_before_single_topic action hook, and I have this all in a revised btv plugin, including your great code.
    This creates a revised version that has just what I want, and adds it as a new line.

    But I now need to get rid of the original bbp_single_topic_description() as this repeats the old line, so I have the right text, followed by the wrong text.

    You say you disabled the “this topic”…etc. How did you do this? Obviously I can simply comment out the code line in content-single-topic, but is there a smarter way to do this so that code is not over-written by later versions?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Initial view count’ is closed to new replies.