• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

Count Views For Manga Chapters

If you don’t understand about coding, this is the full code for lazy ones. Just copy the code and paste it into your child theme /functions.php file. After that, switch to parent theme and the switch back to child theme to activate the code.
 
  • Like
Reactions: trixonv
Use your reading skillz. Another thing you would find out if you kept reading is that the code is also split for different versions. Thing you forgot to mention in your request: what version of madara are you using?
 
Use your reading skillz. Another thing you would find out if you kept reading is that the code is also split for different versions. Thing you forgot to mention in your request: what version of madara are you using?
i use 1.6.5
 
You have to activate child theme after you paste the function.

Also this is the full code that have to be added to functions.php in your child theme

Code:
/**
* 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 '<span class="view"><i class="fa fa-eye"></i> ' . $views . '</span>';
}


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;
}


add_action('wp_manga_after_update_manga_views', 'my_wp_manga_after_update_manga_views');


function my_wp_manga_after_update_manga_views(){


$manga_id = intval($_POST['manga']);
$chapter_slug = '';
if(isset($_POST['chapter']) && $_POST['chapter'] != 'undefined'){
$chapter_slug = $_POST['chapter'];
}


if($chapter_slug != ''){
global $wp_manga_chapter;


$chapter = $wp_manga_chapter->get_chapter_by_slug( $manga_id, $chapter_slug);


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));
}
}


}

As I said, if you have kept reading there is this paragraph: Full code for Madara-Core 1.6+ :
 
  • Love
Reactions: trixonv
thnx alot its working

but i use arabic that mean from right to left if you can tell me how to edit
 

Attachments

  • qzsedzezeqzeqz.png
    qzsedzezeqzeqz.png
    38.7 KB · Views: 68
I don't know how to help you set RTL on this as I don't know madara theme hooks and also don't have time to check it.

I suppose is this trigger:

add_action('wp_manga_after_chapter_name', 'my_manga_chapter_name_info', 10, 2);

but instead of "after_chapter_name" is "before_chapter_name"
 
  • Like
Reactions: testeradm
can you help me too?
Version 1.7.3.1
You have to activate child theme after you paste the function.

Also this is the full code that have to be added to functions.php in your child theme

Code:
/**
* 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 '<span class="view"><i class="fa fa-eye"></i> ' . $views . '</span>';
}


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;
}


add_action('wp_manga_after_update_manga_views', 'my_wp_manga_after_update_manga_views');


function my_wp_manga_after_update_manga_views(){


$manga_id = intval($_POST['manga']);
$chapter_slug = '';
if(isset($_POST['chapter']) && $_POST['chapter'] != 'undefined'){
$chapter_slug = $_POST['chapter'];
}


if($chapter_slug != ''){
global $wp_manga_chapter;


$chapter = $wp_manga_chapter->get_chapter_by_slug( $manga_id, $chapter_slug);


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));
}
}


}

As I said, if you have kept reading there is this paragraph: Full code for Madara-Core 1.6+ :
Add Plugin > Search for Code Snippets > Install > Activate > Copy the code above > Paste it in a PHP tab > Give it a title > Activate.

You'd probably want to also have the child theme of Madara installed and activated to avoid any pesky bugs.
 
my sql table name is njgxm2_
Can you edit the code properly for me? please
PHP:
/**
* Add columns "views" to table njgxm2_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 . 'njgxm2_manga_chapters', 'views')){
$db->alter_add_column($wpdb->prefix . 'njgxm2_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 '<span class="view"><i class="fa fa-eye"></i> ' . $views . '</span>';
}


function manga_get_chapter_views($chapter_id){
global $wpdb;
$sql = "SELECT views from {$wpdb->prefix}njgxm2_manga_chapters WHERE chapter_id=%d" ;


$views = $wpdb->get_var($wpdb->prepare($sql, $chapter_id));


return $views ? $views : 0;
}


add_action('wp_manga_after_update_manga_views', 'my_wp_manga_after_update_manga_views');


function my_wp_manga_after_update_manga_views(){


$manga_id = intval($_POST['manga']);
$chapter_slug = '';
if(isset($_POST['chapter']) && $_POST['chapter'] != 'undefined'){
$chapter_slug = $_POST['chapter'];
}


if($chapter_slug != ''){
global $wp_manga_chapter;


$chapter = $wp_manga_chapter->get_chapter_by_slug( $manga_id, $chapter_slug);


if($chapter){
$chapter_id = $chapter['chapter_id'];
global $wpdb;
$views = manga_get_chapter_views($chapter_id);


$wpdb->update("{$wpdb->prefix}njgxm2_manga_chapters", array('views'=>++$views), array('chapter_id' => $chapter_id));
}
}


}
 
PHP:
/**
* Add columns "views" to table njgxm2_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 . 'njgxm2_manga_chapters', 'views')){
$db->alter_add_column($wpdb->prefix . 'njgxm2_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 '<span class="view"><i class="fa fa-eye"></i> ' . $views . '</span>';
}


function manga_get_chapter_views($chapter_id){
global $wpdb;
$sql = "SELECT views from {$wpdb->prefix}njgxm2_manga_chapters WHERE chapter_id=%d" ;


$views = $wpdb->get_var($wpdb->prepare($sql, $chapter_id));


return $views ? $views : 0;
}


add_action('wp_manga_after_update_manga_views', 'my_wp_manga_after_update_manga_views');


function my_wp_manga_after_update_manga_views(){


$manga_id = intval($_POST['manga']);
$chapter_slug = '';
if(isset($_POST['chapter']) && $_POST['chapter'] != 'undefined'){
$chapter_slug = $_POST['chapter'];
}


if($chapter_slug != ''){
global $wp_manga_chapter;


$chapter = $wp_manga_chapter->get_chapter_by_slug( $manga_id, $chapter_slug);


if($chapter){
$chapter_id = $chapter['chapter_id'];
global $wpdb;
$views = manga_get_chapter_views($chapter_id);


$wpdb->update("{$wpdb->prefix}njgxm2_manga_chapters", array('views'=>++$views), array('chapter_id' => $chapter_id));
}
}


}
1673406426775.png
what's wrong?
 
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock