//Đếm view trong post function codfe_count(){ if ( is_single() || is_page() || is_category() ) : setPostViews(get_the_ID()); endif; } add_action( 'flatsome_after_header', 'codfe_count' ); ////Codfe.com code lấy lượt xem function getPostViews($postID){ //nếu không nhập vào id thì lấy id trang hiện tại if ( $postID == null ) $postID = get_the_ID(); $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); return "01 "; } return $count.' '; } add_shortcode('cf-get-view','getPostViews'); //Codfe.com code đếm lượt xem function setPostViews($postID) { $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ $count = 0; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); }else{ $count++; update_post_meta($postID, $count_key, $count); } } //Codfe.com code hiển thị số lượt xem trong dashboard //page //add_filter('manage_pages_columns', 'posts_column_views'); //add_action('manage_pages_custom_column', 'posts_custom_column_views',5,2); //category //add_filter('manage_edit-category_columns', 'posts_column_views'); //add_action('manage_category_custom_column', 'posts_custom_column_views',5,2); //post add_filter('manage_posts_columns', 'posts_column_views'); add_action('manage_posts_custom_column', 'posts_custom_column_views',5,2); function posts_column_views($defaults){ $defaults['post_views'] = __('Views'); return $defaults; } function posts_custom_column_views($column_name, $id){ if($column_name === 'post_views'){ echo getPostViews(get_the_ID()); } } // Ghi đè hàm hiển thị view trên flatsome // Prints HTML with meta information for the current post-date/time and author. function flatsome_posted_on() { $time_string = ''; if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { $time_string = ''; } $time_string = sprintf( $time_string, esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() ), esc_attr( get_the_modified_date( 'c' ) ), esc_html( get_the_modified_date() ) ); $posted_on = sprintf( esc_html_x( ' %s', 'post date', 'flatsome' ), '' . $time_string . '' ); $byline = sprintf( esc_html_x( ' %s', 'post author', 'flatsome' ), ' ' ); echo '
'; } // hook vào product //add_action( 'woocommerce_product_meta_start','codfe_show_post_view' ); //add_action('flatsome_product_box_after','codfe_show_post_view'); function codfe_show_post_view(){ //echo current_filter().''; if( current_user_can('administrator') ) { echo ' '; } } add_shortcode("codfe-show-post-views","codfe_show_post_view"); // codfe.com - popup //https://codfe.com/tao-popup-bao-gia-bang-lightbox-trong-flatsome/ // menu với link: #bao-gia // them shortcode popup vào header function cf_add_to_header(){ //pop up bao gia echo do_shortcode(' [lightbox id="bao-gia" width="600px" padding="10px"] [block id="popup-bao-gia"] [/lightbox] '); //pop up cam on echo do_shortcode(' [lightbox id="cam-on" width="600px" padding="10px"] [block id="popup-cam-on"] [/lightbox] '); } add_action('flatsome_before_header','cf_add_to_header'); ?>