• Resolved vl4d

    (@vl4d)


    my views count doesn’t work after installing the plugin i dont find any guid how to make the views count on my theme or to be excluded from caching any tips??

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @vl4d

    I am sorry about the issue you are experiencing and I am happy to assist you with this.
    Can you please share the website URL and the theme you are using (or the plugin for views count) so I can check this?
    Thanks!

    Thread Starter vl4d

    (@vl4d)

    i am ussing madara theme (i cant post here the link for my site sorry) this is the demo of my theme https://mangabooth.com/ https://live.mangabooth.com/

    if helps this is the extra code for the views i have on functions

    /**
    * Add columns “views” to table manga_chapters
    **/
    //add_action("after_switch_theme", "my_manga_add_columns");
    //function my_manga_add_columns(){
    //global $wpdb;
    
    //$db = WP_MANGA_DATABASE::get_instance();
    //if(!$db->column_exists($wpdb->prefix . 'manga_chapters', 'views')){
    //$db->alter_add_column($wpdb->prefix . 'manga_chapters', 'views', 'int');
    //}
    //}
    
    /**
    * Show the views
    **/
    add_action('wp_manga_after_chapter_name', 'my_manga_chapter_name_info', 10, 2);
    
    function my_manga_chapter_name_info($chapter, $manga_id){
    $views = manga_get_chapter_views($chapter['chapter_id']);
    
    echo '<i style="margin-right:50px;"><span class="view"><i class="fa fa-eye"></i> ' . $views . '</span></i>';
    }
    
    function manga_get_chapter_views($chapter_id){
    global $wpdb;
    $sql = "SELECT views from {$wpdb->prefix}manga_chapters WHERE chapter_id=%d" ;
    
    $views = $wpdb->get_var($wpdb->prepare($sql, $chapter_id));
    
    return $views ? $views : 0;
    }
    
    /**
    * Increase the views
    **/
    add_action('after_manga_single', 'my_manga_chapter_views');
    function my_manga_chapter_views(){
    $cur_chap = get_query_var( 'chapter' );
    $manga_id = get_the_ID();
    
    if($cur_chap != ""){
    global $wp_manga_chapter;
    
    $chapter = $wp_manga_chapter->get_chapter_by_slug( $manga_id, $cur_chap );
    
    if($chapter){
    $chapter_id = $chapter['chapter_id'];
    global $wpdb;
    $views = manga_get_chapter_views($chapter_id);
    
    $wpdb->update("{$wpdb->prefix}manga_chapters", array('views'=>++$views), array('chapter_id' => $chapter_id));
    }
    }
    }
    • This reply was modified 3 years, 1 month ago by vl4d.
    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @vl4d

    Thank you for the information.
    Indeed the problem is that the views count is cached. The solution for this is programmatic.
    There are two ways t approach this. The best way is to use AJAX and execute the view count with it to bypass any cache
    As a reference, you may check how other plugins/themes show dynamic data e.g. Woocommerce shows their shopping cart widget.
    Widget content is loaded via AJAX there with some support of local browser storage and as a result, they avoid the majority of problems with all caching plugins.
    The other possibility is to use Page Fragment Cache. With this, the specific part of the PHP code can be wrapped with <mfunc> which ensures that this part of the page stays uncached.
    Please check more information in our FAQ.
    I hope this helps!
    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘views count problem’ is closed to new replies.