• Resolved qnkov

    (@qnkov)


    Hello there. Is there a way to add those counts in the pages? Like, when you open any page, to have like Total views, views today and etc…. like that.

    https://prnt.sc/qqehkh

    I would like to remove the other counting plugin and leave only yours, cuz i have it as gadget, but i need it in pages too. I’ve tried the code in other thread that you put in function.php, but nothing happens. It’s blank, if i remove it, i can see the shortcode.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi there,

    I don’t remember how that [wpp_views_count] worked to be honest so if you could share the link to the topic where you saw it I might be able to help out.

    Plugin Author Hector Cabrera

    (@hcabrera)

    Nevermind, I found the topic: Show wpp_get_views() with shortcode. I forgot I even pinned it haha.

    The reason why that shortcode doesn’t work on pages is because it’s using the is_single() conditional which doesn’t work for pages. Change it to is_singular() and it’ll work for pages too:

    /**
     * Registers the shortcode [wpp_views_count].
     *
     * @author Hector Cabrera (https://cabrerahector.com)
     * @return string
     */
    function wpp_views_count_func() {
        if (
            function_exists('wpp_get_views')
            && is_singular()
        ) {
            $views_count = wpp_get_views( get_the_ID() );
            return ($views_count == 1) ? '1 view' : $views_count . ' views';
        }
    
        return '';
    }
    add_shortcode( 'wpp_views_count', 'wpp_views_count_func' );
    Thread Starter qnkov

    (@qnkov)

    Yes, this way shows overall count. You plan to update it to show overall, and today views on pages? Something better looking?
    https://prnt.sc/qqwu3k

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

    (@hcabrera)

    Yes, this way shows overall count.

    Awesome, thanks for reporting back.

    You plan to update it to show overall, and today views on pages? Something better looking?

    No, I have no plans to do that as that shortcode was something I wrote for another plugin user on request. It’s not part of the main plugin.

    If you want to extend it and/or improve its design you’re free to do so. Check the documentation of the wpp_get_views() function to learn how to get data for other time ranges.

    If you have any other questions don’t hesitate to ask.

    Thread Starter qnkov

    (@qnkov)

    That’s hard for me. If you can fast update it the way i need it, would be awesome. Even if you can enable it in your pages by placing it top, mid and bottom. If not, everything is fine. ??

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

    (@hcabrera)

    Alright, I’ll help you out a bit.

    To have the shortcode display total views + views from the last 24 hours you can do this:

    /**
     * Registers the shortcode [wpp_views_count].
     *
     * @author Hector Cabrera (https://cabrerahector.com)
     * @return string
     */
    function wpp_views_count_func() {
        if (
            function_exists('wpp_get_views')
            && is_singular()
        ) {
            $total_views_count = wpp_get_views(get_the_ID());
            $total_views_count = (1 == $total_views_count) ? '1 view' : $total_views_count . ' views';
    
            $views_count_from_last_7_days = wpp_get_views(get_the_ID(), 'last7days');
            $views_count_from_last_7_days = (1 == $views_count_from_last_7_days) ? '1 view' : $views_count_from_last_7_days . ' views';
    
            return "<strong>Total views:</strong> {$total_views_count} | <strong>Last 7 days:</strong> {$views_count_from_last_7_days}";
        }
    
        return '';
    }
    add_shortcode('wpp_views_count', 'wpp_views_count_func');
    Thread Starter qnkov

    (@qnkov)

    THanks man, but you have made it for 7 days. I think i’ve corrected it like that.

    /**
     * Registers the shortcode [wpp_views_count].
     *
     * @author Hector Cabrera (https://cabrerahector.com)
     * @return string
     */
    function wpp_views_count_func() {
        if (
            function_exists('wpp_get_views')
            && is_singular()
        ) {
            $total_views_count = wpp_get_views(get_the_ID());
            $total_views_count = (1 == $total_views_count) ? '1 преглед' : $total_views_count . ' прегледа';
    
            $views_count_from_last_24_hours = wpp_get_views(get_the_ID(), 'last24hours');
            $views_count_from_last_24_hours = (1 == $views_count_from_last_24_hours) ? '1 преглед' : $views_count_from_last_24_hours . ' прегледа';
    
            return "<strong>Прегледа общо:</strong> {$total_views_count} | <strong>Прегледа днес:</strong> {$views_count_from_last_24_hours}";
        }
    
        return '';
    }
    add_shortcode('wpp_views_count', 'wpp_views_count_func');

    If possible, can you tell me if we can make it to count per ip or something only for today, not per click.
    And is there a way to put that code somewhere so i get it in all pages, so i won’t put it 1 by 1 on 1000 pages and of course a way to exclude it from certain pages.

    Thanks. I think that should be good update, cuz its useful.

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

    (@hcabrera)

    If possible, can you tell me if we can make it to count per ip or something only for today, not per click.

    It’s doable, yes, but this is something that requires a bit of coding and testing as it’s not a feature included in the plugin. You’ll have to hire a developer for this one.

    And is there a way to put that code somewhere so i get it in all pages, so i won’t put it 1 by 1 on 1000 pages and of course a way to exclude it from certain pages.

    Yes, there is. Have a look at the_content filter hook.

    Thread Starter qnkov

    (@qnkov)

    I see. Do you have any email or way to contact you?

    Plugin Author Hector Cabrera

    (@hcabrera)

    I do. Click on my profile picture for more details.

    Mind you though, if you plan to contact me to help you with the IP address thing I’m afraid I’ll have to turn you down. I’m currently busy with other projects and so I’m not taking any freelance job offers for now.

    Thread Starter qnkov

    (@qnkov)

    I see, thanks. I’ve wrote to you in your form.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Adding counts in pages?’ is closed to new replies.