bbPress

Simple, Fast, Elegant

bbPress plugin browser »

Post Count (.73a)

Download

Version: .73a

Other Versions

Last Updated: 2007-1-12

Requires bbPress Version: .73 ? or higher

Compatible up to: .74

Author Homepage »

Plugin Homepage »

Average Rating

5 stars
4 stars
3 stars
2 stars
1 star
(6)

Your Rating

Author: Josh Hutchins

Plugin Name: Show Post Count Plugin URI: http://faq.rayd.org/bbpresspostcount/ Description: Allows post count to be easily displayed, just add postcount() wherever you want it Author: Joshua Hutchins Author URI: http://ardentfrost.rayd.org/ Version: .73a


  1. Tried implementing this in the profile, had a problem. Seems like it has to be used in the equivalent of the loop? But it was easy to modify. I simply changed function post_code() to:

    function post_count( $id = '' ) 	{
    	if (  get_post_author_id() ) 	{
    		echo get_post_count( get_post_author_id() );	}
    	elseif ( isset( $id ) )		{
    		echo get_post_count( $id );		}
    	else	{
    		echo 'Error';	}
    }

    meaning that if you wanted to call it in a user profile all you had to do is pass $user->ID as a parameter.

    I like the plugin, but it would be good if you could update it with this or something similar. :)

    Posted: 1 year ago #
  2. Odd, I use mine in my profile pages. Of course, I use my second function to pull it out.

    Not a bad idea to make it more usable with profile pages, I'll work on this for the next release.

    Posted: 1 year ago #
  3. afrodude

    Inactive

    Where do I insert this code?

    Posted: 1 year ago #
  4. Does this display the total number of posts in the entire forum, the number of posts a user has posted, or ?

    Posted: 1 year ago #
  5. afrodude: I put mine in post.php, under the author_link

    <?php if (function_exists('post_count')) { ?>
    <small><em><?php post_count() ?></em></small>
    <?php } ?>

    That way, if I ever decide to remove it, it won't muck up my template. :)

    Posted: 1 year ago #
  6. Thanks for this plugin. I'm using it just in my post.php using the code Nitallica posted.

    Posted: 1 year ago #
  7. I modified this plugin to be a little more efficient. In the original version, if you have a topic with 30 replies between two people, you'd end up with 30 SQL statements that fetch the entire set of posts for each user. Not terribly efficient.

    I changed it to use the count(*) instead, and also to cache those counts in a hashtable instead. That way the topic with 30 replies between two people would only have 2 sql statements executed, not 30. Still not perfect, but quite a bit better. I also removed the error notice.

    Here's the full code, which you are welcome to change as much as you want:


    $htg_postcount = array();

    function post_count() {
    if ( get_post_author_id() )
    echo 'Posts: ' . get_post_count( get_post_author_id() );
    else
    echo '';
    }

    function get_post_count ( $id ) {
    global $bbdb;
    global $htg_postcount;
    if($htg_postcount[$id]==''){
    $htg_postcount[$id] = $bbdb->get_var("SELECT count(*) FROM $bbdb->posts WHERE poster_id = $id AND post_status = 0");
    }
    return $htg_postcount[$id];
    }

    Posted: 12 months ago #
  8. In case anyone is having trouble adding the post count to profile pages I modified HowToGeek's code to work in both profiles and posts. Here goes:

    $htg_postcount = array();
    
    function post_count() {
    if ( get_post_author_id() )
    	echo 'Posts: ' . get_post_count( get_post_author_id() );
    else if ( bb_get_current_user_info( 'id' ) )
    	echo '<strong>Posts</strong>' . get_post_count( bb_get_current_user_info( 'id' ) );
    echo '';
    }
    
    function get_post_count ( $id ) {
    global $bbdb;
    global $htg_postcount;
    if($htg_postcount[$id]==''){
    $htg_postcount[$id] = $bbdb->get_var("SELECT count(*) FROM $bbdb->posts WHERE poster_id = $id AND post_status = 0");
    }
    return $htg_postcount[$id];
    }

    Just place <?php post_count() ?> in posts.php and/or profile.php anywhere you want.

    I placed mine in the following locations:

    in profile.php:

    <?php bb_profile_data(); ?>
    
    <?php profile_last_online(); ?>
    
    <?php post_count() ?>

    and in post.php:

    <strong><?php post_author_link(); ?></strong>
    			  <small><?php post_author_title(); ?></small>
    			  <?php post_count() ?>
    Posted: 6 months ago #
  9. Oh my, I missed a big problem with the code above. That shows the current users post count on everyone's profile. Here is the correct code:

    $htg_postcount = array();

    function post_count($id = null) {
    if ( get_post_author_id() && $id == null)
    echo 'Posts: ' . get_post_count( get_post_author_id() );
    else if ( !get_post_author_id() && $id != null )
    echo 'Posts' . get_post_count( $id );
    else
    echo 'error';
    }

    function get_post_count ( $id ) {
    global $bbdb;
    global $htg_postcount;
    if($htg_postcount[$id]==''){
    $htg_postcount[$id] = $bbdb->get_var("SELECT count(*) FROM $bbdb->posts WHERE poster_id = $id AND post_status = 0");
    }
    return $htg_postcount[$id];
    }

    With this code you must put this on your profile page: <?php post_count($user->ID) ?> and this on your post page: <?php post_count() ?>

    Posted: 6 months ago #

RSS feed for this topic

Add a Comment

You must log in to post.

Code is Poetry.