Chuyên mục

How to

71 bài viết

How to

Chuyển chuỗi sang dạng HTML và loại bỏ các thẻ style và script trong wordpress

$excerpt = get_the_permalink(); $limit_excerpt = wp_trim_words( $excerpt, 10, '…' ); echo wp_strip_all_tags( $limit_excerpt, true ); Trong đoạn mã trên có hàm: wp_strip_all_tags sử dụng để chuyển các chuỗi sang html Hàm này sử dụng khi: gọi các dữ liệu từ database ra giao diện web

23/12/2020·1 phút đọc
How to

Lấy danh sách bài viết theo chuyên mục

Style 1: <?php add_shortcode( 'catlist', 'tmdev_create_module_catlist' ); function tmdev_create_module_catlist($atts){ extract( shortcode_atts( array( 'title' => '', 'slug' => '', 'taxonomy' => 'category', 'post__in' => '', 'limit' => 3 ), $atts, 'catlist' ) ); $terms = array(); $terms = array_map( 'trim', explode( ',', $slug ) ); if( empty( $terms ) ) return ''; $args = array( 'post_type' […]

23/12/2020·2 phút đọc
How to

Tạo danh sách bài viết liên quan

<?php $post_id = get_the_ID(); $related_query = new WP_Query(array( 'post_type' => 'post', 'category__in' => wp_get_post_categories( $post_id ), 'post__not_in' => array( $post_id ), 'posts_per_page' => 8 )); ?> <?php if ($related_query->have_posts()) { ?> <div class="related-posts-grid"> <h2>Bài viết liên quan</h2> <?php while ($related_query->have_posts()) { ?> <?php $related_query->the_post(); ?> <div class="grid-item"> <a href="<?php the_permalink(); ?>"> <?php the_post_thumbnail('post-thumb-small'); ?> </a> […]

23/12/2020·1 phút đọc
How to

Hướng dẫn lấy id chuyên mục hiện tại trong trang taxonomy

Cách lấy ID của chuyên mục bài viết hoặc ID của chuyên mục Custom Post Type Để lấy ID của chuyên mục các bạn hãy làm như sau. Trong trang chuyên mục bạn dán đoạn mã: <?php $current_term = get_queried_object(); $current_term_id = $current_term->term_id; ?> Kết quả trả về của hàm get_queried_object(); trong trang chuyên mục sẽ tương tự […]

23/12/2020·1 phút đọc
How to

Tạo thêm trường comment

https://www.smashingmagazine.com/2012/05/adding-custom-fields-in-wordpress-comment-form/

10/12/2020·1 phút đọc
How to

Chuyển ảnh khi rê chuột vào sản phẩm trong woocommerce

add_action( 'woocommerce_before_shop_loop_item_title', 'add_on_hover_shop_loop_image' ) ; function add_on_hover_shop_loop_image() { $image_id = wc_get_product()->get_gallery_image_ids()[1] ; if ( $image_id ) { echo wp_get_attachment_image( $image_id ) ; } else { //assuming not all products have galleries set echo wp_get_attachment_image( wc_get_product()->get_image_id() ) ; } } /* CUSTOM ON-HOVER IMAGE */ .woocommerce ul.products li.product a img { /* FORMAT ALL IMAGES TO […]

29/10/2020·1 phút đọc
How to

Hướng dẫn sử dụng plugin WP All Import XML / CSV để nhập bài viết

Tóm tắt quá trình thực hiện gồm 2 bước chính: B1/ Xuất bản các bài viết ở website cũ ra file csv B2/ Nhập các bài biết ở website cũ sang website mới B1/ Xuất bản các bài viết ở website cũ ra file csv Cài plugin WP All Export Pro Cấu hình export post type […]

16/10/2020·2 phút đọc
How to

Hướng dẫn cấu hình chuyển hướng tên miền khác thư mục khác tên miền

Giả sử website mới ( http://newdomain.com ) có thư mục: Tin tức công nghê (tin-cong-nghe), Website cũ có thư mục: Tin tức (tin-tuc), Bây giờ ta muốn chuyển tất cả các bài viết trong chuyên mục Tin tức website cũ sang thư mục tin công nghệ của website mới ta làm các bước như sau: […]

13/10/2020·1 phút đọc
How to

Zip tất cả các file trong cùng thư mục

function tm_zip_all_barcode(){ $upload_dir = wp_upload_dir(); // Get real path for our folder $rootPath = $upload_dir['basedir'].'/barcode'; // Initialize archive object $zip = new ZipArchive(); $zip->open($upload_dir['basedir'].'/barcode.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE); // Create recursive directory iterator /** @var SplFileInfo[] $files */ $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($rootPath), RecursiveIteratorIterator::LEAVES_ONLY ); foreach ($files as $name => $file) { // Skip directories […]

30/09/2020·1 phút đọc