BuddyDev

Search

[Resolved] Buddyblog post views counter

  • Participant
    Level: Guru
    Posts: 886
    Tosin on #44250

    Hello,

    Please can you add a feature to display the post views count for this plugin(https://wordpress.org/plugins/post-views-counter/). Some sort of analytics would be helpful in giving content creators feedback on the views of their post.

    see example image below
    https://ibb.co/f9KxjjR

    Also same feature can be added in the post layout feature I suggested at https://buddydev.com/support/forums/topic/buddypress-user-blog-post-manager-layout-suggestion/

    Thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24238
    Brajesh Singh on #44254

    Hi Tosin,
    Thank you.

    We haven’t checked the plugin but it should work fine for BuddyBlog Pro.
    If it is not, Please let me know and we will investigate/add custom support.

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 886
    Tosin on #44261

    The plugin works fine in single post pages as seen here https://imgur.com/a/MMlNhhu

    But displaying it in the post management section is the issue (A setting option to enable the display would be awesome when buddyblog detects the installation of the post views counter plugin)

  • Keymaster
    (BuddyDev Team)
    Posts: 24238
    Brajesh Singh on #44275

    Thank you Tosin.

    Please allow me to check and get back to you in next 2 days. For the time being, I/Ravi will be supplying some custom code to achieve it. In future, we will be happy to add support inside the plugin.

    Regards
    Brajesh

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2945
    Ravi on #44292

    Hello Tosin,

    Try the following code:

    
    add_filter( 'pvc_display_views_count', function( $display ) {
    
    	if ( ! function_exists( 'buddyblog_pro' ) ) {
    		return $display;
    	}
    
    	$pvc = Post_Views_Counter();
    
    	if ( empty( $pvc->options['display'] ) || empty( $pvc->options['display']['post_types_display'] ) ) {
    		return $display;
    	}
    
    	$current_post_type = bblpro_get_current_post_type();
    
    	if ( ! $display && $current_post_type && in_array( $current_post_type, (array) $pvc->options['display']['post_types_display'] ) ) {
    		$display = true;
    	}
    
    	return $display;
    } );
    
    add_filter( 'the_excerpt', function ( $excerpt ) {
    
    	if ( ! function_exists( 'Post_Views_Counter' ) ) {
    		return $excerpt;
    	}
    
    	return Post_Views_Counter()->frontend->add_post_views_count( $excerpt );
    } );
    
    

    It will append the view count on the archive page.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 886
    Tosin on #44300

    Hello Ravi,

    I added the code to functions.php file but it does not display the count like this https://ibb.co/f9KxjjR

    The count does not display at all in users page.

    Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2945
    Ravi on #44311

    Hello Tosin,

    Thank you for your acknowledgement. I have rechecked this on my local development server and it is working fine for me. Please have a look:

    https://www.awesomescreenshot.com/image/25345015?key=d592c187c63529f4afc2015e70945eeb

    Please try after switching to the default theme temporarily and let me know if it is showing there or not.

    Please make sure you have selected the post type under plugin settings > Display > Post Type.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 886
    Tosin on #44318

    Hello,

    The issue came from > Display > Position= Manual. When I changed it to either After Content or Before Content the count displayed.

    The problem now I want to use the Manual position because I added the post views code (<?php echo pvc_post_views(); ?>) directly into my theme’s content-single.php file.

    Can you make the code to work for manual position

    Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2945
    Ravi on #44319

    Hello Tosin,

    Please try the following code instead of calling the direct function as mentioned by the plugin author.

    
    echo do_shortcode( '[post-views]' );
    

    You can pass the ‘id’ if not work.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 886
    Tosin on #44342

    Now the excerpt is missing

     add_filter( 'the_excerpt', function ( $excerpt ) {
    	if ( ! function_exists( 'Post_Views_Counter' ) ) {
    		return $excerpt;
    	}
    	echo do_shortcode( '[post-views]' );
    } ); 

The topic ‘ [Resolved] Buddyblog post views counter’ is closed to new replies.

This topic is: resolved