Support » Plugin: WordPress Popular Posts » 1000 views to show as 1K

  • Resolved victorrest

    (@victorrest)


    Hi
    Is there any method to show the views on the posts like:
    1000 = 1k
    1500 = 1.5K
    10000 = 10K
    etc…

    I use this code to show the counter on the posts:

    <?php
    if ( function_exists('wpp_get_views') ) {
        echo wpp_get_views(get_the_ID());
    }
    ?>

    The page I need help with: https://liked.hu

    • This topic was modified 2 years, 7 months ago by victorrest.
    • This topic was modified 2 years, 7 months ago by victorrest.
    • This topic was modified 2 years, 7 months ago by victorrest.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @victorrest,

    This should work:

    <?php
    if ( function_exists('wpp_get_views') ) {
        echo WordPressPopularPosts\Helper::prettify_number(wpp_get_views(get_the_ID(), 'all', false));
    }
    ?>
    Thread Starter victorrest

    (@victorrest)

    Thank you so much Héctor, it’s work fine! 🙂

    I would be glad if the counter only display at the posts if the current post view is more than 1000, may have any solution for this?

    Best regards

    • This reply was modified 2 years, 7 months ago by victorrest.
    Plugin Author Hector Cabrera

    (@hcabrera)

    Thank you so much Héctor, it’s work fine!

    Don’t mention it 🙂

    I would be glad if the counter only display at the posts if the current post view is more than 1000, may have any solution for this?

    Yep, try this:

    <?php
    if ( function_exists('wpp_get_views') ) {
        // Get pageviews count
        $pageviews = wpp_get_views(get_the_ID(), 'all', false);
    
        // Post has more than 1000 views, display views count
        if ( $pageviews >= 1000 )
            echo WordPressPopularPosts\Helper::prettify_number($pageviews);
    }
    ?>
    Thread Starter victorrest

    (@victorrest)

    Work like a charm, thank you so much. 🙂

    How can i show 1.000 instead of 1k on wordpresspopular posts top 10 widget?

    • This reply was modified 2 years, 5 months ago by incitmemeli.
    Plugin Author Hector Cabrera

    (@hcabrera)

    Check this, @incitmemeli.

    Thank you solved 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘1000 views to show as 1K’ is closed to new replies.