• Resolved Maurizio Zani

    (@mauriziozani)


    Hi, someone knows how to shows in each post, other than the data and the author, the number of visits and the number of comments?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi there,

    You will first need to find a plugin for the visit counts option then we can help you add it in – ideally the plugin would offer a shortcode option.

    Let me know ??

    Thread Starter Maurizio Zani

    (@mauriziozani)

    Thanks Leo. I’m already using WP-PostViews, that was working with the previous theme Atahualpa. Is this the shortcode you are referring to?

    the_views()

    • This reply was modified 3 years, 11 months ago by Maurizio Zani.

    I think this is the method we will go with:
    https://generatepress.com/forums/topic/post-visit-counter-and-mins-read-time/page/2/#post-1586449

    So add:

    add_action( 'generate_post_meta_items', function( $item ) {
        if ( 'view-counter' === $item ) {
            echo '<span class="view-counter">Post views ' . the_views() . '</span>';
        }
    } );
    
    add_filter( 'generate_header_entry_meta_items', function() {
        return array(
            'author',
            'date',
            'view-counter',
            'comments-link',
        );
    } );
    
    add_action( 'wp', function() {
        if ( is_single() ) {
            add_filter( 'generate_show_comments', '__return_true' );
        }
    } );

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    Thread Starter Maurizio Zani

    (@mauriziozani)

    Leo, it’s working! I’ve modified it just a bit:

    add_action( 'generate_post_meta_items', function( $item ) {
        if ( 'view-counter' === $item ) {
    		echo ' - ';
    		echo '<span class="view-counter"> ' . the_views() . ' - </span>';
        }
    } );
    
    add_filter( 'generate_header_entry_meta_items', function() {
        return array(
            // 'author',
            'date',
            'view-counter',
            'comments-link',
        );
    } );
    
    add_action( 'wp', function() {
        if ( is_single() ) {
            add_filter( 'generate_show_comments', '__return_true' );
        }
    } );

    PS: I’ve seen your gentle and generous contribution on this free forum and on the other one (reserved, but open), thanks again. I’ve decided to subscribe to GeneratePress

    • This reply was modified 3 years, 11 months ago by Maurizio Zani.
    • This reply was modified 3 years, 11 months ago by Maurizio Zani.

    Awesome job!

    Thank you for the kind words ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Show number of visits and number of comments’ is closed to new replies.