• Resolved NAROLLES

    (@narolles)


    Hello Hector
    Glad to see you again….

    I’m watching your evolutions for elementor….I’ll try to move forward by looking at the posts concerned when I can focus on it. If one day you have the idea of making a turnkey solution .. it will be great.

    For the past few days, I have encountered an error that is not permanent….maybe it comes from WPP, but maybe from elsewhere
    I see this error: Failed to load resource: the server responded with a status of 403 () /wp-json/wordpress-popular-posts/v1/popular-posts

    Finally incidentally How can I put with this short code [wpp_counter_view] the expression “views” just after … currently I tinker

    Thank you and good continuation

    The page I need help with: [log in to see the link]

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

    (@hcabrera)

    Hi @narolles,

    For the past few days, I have encountered an error that is not permanent….maybe it comes from WPP, but maybe from elsewhere
    I see this error: Failed to load resource: the server responded with a status of 403

    This might be caused by the WP Rocket plugin. Please see Is WordPress Popular Posts compatible with caching plugins? and make sure to follow the recommendations listed there.

    How can I put with this short code [wpp_counter_view] the expression “views” just after

    Assuming you’re talking about this function, all you need to do is to add the “views” text after the views count, like so for example:

    function wpp_viewcounter ($option) {
        if (function_exists("wpp_get_views") ) {
            $nbView = wpp_get_views(get_the_ID(), 'all');
            $iNbView = intval(preg_replace("/[^0-9]/", "", $nbView));
            return colorCounterView($iNbView) . ' views';
        }
    }
    add_shortcode('wpp_counter_view', 'wpp_viewcounter');
    Thread Starter NAROLLES

    (@narolles)

    Hi Hector

    For the function….

    I adapted this existing function instinctively
    it works
    just how to put a space between the number and the "views" label
    if I was more manic I would put an option to put the label in the singular when there is only one view....but hey, we can do without it.....
    can you confirm me the writing of the last line Thank you

    `
    function wpp_viewcounter ($option)
    {
    if (function_exists(‘wpp_get_views’) )
    {
    $nbView = wpp_get_views(get_the_ID());
    $iNbView = intval(preg_replace(“/[^0-9]/”,””,$nbView));
    echo colorCounterView($iNbView);
    }
    }
    add_shortcode(‘wpp_counter_view’, ‘wpp_viewcounter’);
    function colorCounterView($number)
    {
    $counterColorBegin=””;
    $counterColorEnd=””;
    $num= intval(preg_replace(“/[^0-9]/”,””,$number));
    if ($num >100)
    {
    $counterImportant = “”;
    if ($num >100) {$counterImportant = ‘-normal’;}
    if ($num >300) {$counterImportant = ‘-good’;}
    if ($num >500) {$counterImportant = ‘-verygood’;}
    if ($num >1000) {$counterImportant = ‘-important’;}
    if ($num >2000) {$counterImportant = ‘-veryimportant’;}
    $counterColorBegin='<span class=”eye-counter-color’.$counterImportant.'”>’;
    $counterColorEnd='</span>’;
    }
    else {
    if (strlen($number)> 4) {
    $counterImportant = ‘-veryimportant’;
    $counterColorBegin='<span class=”eye-counter-color’.$counterImportant.'”>’;
    $counterColorEnd='</span>’;
    }
    }
    return $counterColorBegin . $number . $counterColorEnd . $iNbView . ‘vues’;

    }

    Plugin Author Hector Cabrera

    (@hcabrera)

    There are a few issues with your code so I took the liberty to clean it up a bit. Also added some code lines to make sure that the views count is displayed correctly (singular vs plural).

    Have a look:

    function wpp_viewcounter($option)
    {
        if ( function_exists('wpp_get_views') )
        {
            $nbView = wpp_get_views( get_the_ID() );
            $iNbView = intval( preg_replace("/[^0-9]/", "", $nbView) );
            return colorCounterView($iNbView);
        }
    }
    add_shortcode( 'wpp_counter_view', 'wpp_viewcounter' );
    
    function colorCounterView($number)
    {
        $counterColorBegin = "";
        $counterColorEnd = "";
        $num = intval( preg_replace("/[^0-9]/", "", $number) );
    
        if ( $num > 100 )
        {
            $counterImportant = "";
            if ($num >100) {$counterImportant = '-normal';}
            if ($num >300) {$counterImportant = '-good';}
            if ($num >500) {$counterImportant = '-verygood';}
            if ($num >1000) {$counterImportant = '-important';}
            if ($num >2000) {$counterImportant = '-veryimportant';}
    
            $counterColorBegin ='<span class="eye-counter-color' . $counterImportant .'">';
            $counterColorEnd = '</span>';
        }
        else {
            if ( strlen($number) > 4 ) {
                $counterImportant = '-veryimportant';
                $counterColorBegin ='<span class="eye-counter-color' . $counterImportant .'">';
                $counterColorEnd ='</span>';
            }
        }
    
        $views = sprintf(
            _n('%s view', '%s views', $number, 'wordpress-popular-posts'),
            $number
        );
    
        return $counterColorBegin . $views . $counterColorEnd;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Json 403’ is closed to new replies.