• Về minhduy.vn
  • Đăng ký Hosting
  • Thiết kế Website
  • Khuyến mãi HOT
Hướng Dẫn Sử Dụng Dịch Vụ - Minh Duy Solutions
  • Trang chủ
  • Hosting
    • Hướng dẫn Hosting cPanel
    • Hướng dẫn Hosting DirectAdmin
  • Tên miền
  • Website
    • Hướng dẫn WordPress
    • Hướng dẫn Webmaster
  • Email Doanh Nghiệp
    • Office 365
    • Google Work Space
    • Email Zimbra
  • VPS – Máy chủ
    • Hướng dẫn Linux
    • Hướng dẫn DirectAdmin
  • Hướng dẫn chung
  • Góc ICT
No Result
View All Result
  • Trang chủ
  • Hosting
    • Hướng dẫn Hosting cPanel
    • Hướng dẫn Hosting DirectAdmin
  • Tên miền
  • Website
    • Hướng dẫn WordPress
    • Hướng dẫn Webmaster
  • Email Doanh Nghiệp
    • Office 365
    • Google Work Space
    • Email Zimbra
  • VPS – Máy chủ
    • Hướng dẫn Linux
    • Hướng dẫn DirectAdmin
  • Hướng dẫn chung
  • Góc ICT
No Result
View All Result
Hướng Dẫn Sử Dụng Dịch Vụ - Minh Duy Solutions
No Result
View All Result
Home Hướng dẫn Website Hướng dẫn WordPress

Code widget hiển thị tỷ giá ngoại tệ của Vietcombank

Minh Duy Solutions by Minh Duy Solutions
04/03/2023
Reading Time: 3 mins read
183 9
A A
0
Code widget hiển thị tỷ giá ngoại tệ của Vietcombank

Code widget hiển thị tỷ giá ngoại tệ của Vietcombank

596
SHARES
1.9k
VIEWS
Share on FacebookShare on Twitter

Hôm nay mình xin chia sẻ đoạn code hiển thị tỷ giá ngoại tệ của Vietcombank

function tygiangoaite_vcb() {
    ob_start();
    ?>
        <table class="table table-hover">
            <thead>
                <tr>
                    <th colspan="5" style="text-align:center"><h2>TỶ GIÁ NGOẠI TỆ</h2></th>
                </tr>
                <tr>
                    <th>MÃ NGOẠI TỆ</th>
                    <th>TÊN NGOẠI TỆ</th>
                    <th>MUA TIỀN MẶT</th>
                    <th>MUA CHUYỂN KHOẢN</th>
                    <th>BÁN</th>
                </tr>
            </thead>
            <tbody>
                <?php
            function check_broken_link($url){
                $handle   = curl_init($url);
                if (false === $handle)
                {
                    return false;
                }
                curl_setopt($handle, CURLOPT_HEADER, false);
                curl_setopt($handle, CURLOPT_FAILONERROR, true);  // this works
                curl_setopt($handle, CURLOPT_NOBODY, true);
                curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
                $connectable = curl_exec($handle);
                curl_close($handle);    
                return $connectable;
            }
            $url = "http://www.vietcombank.com.vn/exchangerates/ExrateXML.aspx";
            $thoi_gian_cap_nhat = "";
            if(check_broken_link($url) === TRUE){
                $xml = file_get_contents($url);
                $data = simplexml_load_string($xml);
                if ($data === false) {
                    echo '<tr class="danger"><th colspan="5" style="text-align:center"><h5>DỮ LIỆU BỊ LỖI</h5></th></tr>';
                }
                else {										
                    $thoi_gian_cap_nhat = $data->DateTime;
                    $ty_gia = $data->Exrate;
                    $i=1;
                    foreach($ty_gia as $ngoai_te) {
                        $ma = $ngoai_te['CurrencyCode'];
                        $ten = $ngoai_te['CurrencyName'];
                        $gia_mua = $ngoai_te['Buy'];
                        $gia_chuyen_khoan = $ngoai_te['Transfer'];
                        $gia_ban = $ngoai_te['Sell'];
                        $class_color = "success";
                        if($i%2 == 0){ $class_color = "info";}
                        echo "<tr class='".$class_color."'>";
                        echo "<td>".$ma."</td>";
                        echo "<td>".$ten."</td>";
                        echo "<td>".$gia_mua."</td>";
                        echo "<td>".$gia_chuyen_khoan."</td>";
                        echo "<td>".$gia_ban."</td>";
                        echo "</tr>";
                        $i++;
                    }
                }
            }
            else{
                echo '<tr class="danger"><th colspan="5" style="text-align:center"><h5>KHÔNG THỂ KẾT NỐI ĐẾN MÁY CHỦ VIETCOMBANK</h5></th></tr>';
            }
                ?>
            </tbody>

            <tfoot>
                <?php if($thoi_gian_cap_nhat != ""){
                    $thoi_gian_cap_nhat = date_format(date_create($thoi_gian_cap_nhat),'H:i:s d-m-Y');
                    $thoi_gian_cap_nhat = explode(' ', $thoi_gian_cap_nhat);
                    $gio = $thoi_gian_cap_nhat[0];
                    $ngay = $thoi_gian_cap_nhat[1];
                ?>
                <tr>
                    <th colspan="5">Tỷ giá được cập nhật lúc <?php echo $gio; ?> ngày <?php echo $ngay; ?> và chỉ mang tính chất tham khảo.</th>
                </tr>
                <?php } ?>
            </tfoot>

        </table>
<?php
        $tygia_vcb = ob_get_contents();
        ob_end_clean();

        return $tygia_vcb;	
}
add_shortcode('tygiangoaite_vcb','tygiangoaite_vcb');

Cách sử dụng:

  1. Bạn truy cập vào Giao diện -> Sửa giao diện -> chọn functions.php của theme đang dùng. Dán code vào
  2. Bước tiếp theo là chèn shortcode [tygiangoaite_vcb]  vào nơi bạn muốn hiển thị

Note: Nếu chèn vèo widget mà không hiển thị, bạn chèn thêm code sau vào functions.php của theme đang dùng.

add_filter( 'widget_text', 'do_shortcode' );

Cảm ơn đã ghé thăm!

4.7/5 - (130 bình chọn)
Tags: tỷ giángoại tệvietcombank
Share238Tweet149
Minh Duy Solutions

Minh Duy Solutions

Bài viết liên quan

stop wordpress user registration spam
Hướng dẫn WordPress

Hướng dẫn xoá hàng loạt user spam trên WordPress

23/05/2025
1.5k
thanh top woo c
Hướng dẫn Website

Hướng dẫn ẩn thanh Edit Product che mất tùy chọn khi đăng sản phẩm của WooComerce

24/09/2024
1.6k
flatsome theme 1
Hướng dẫn Website

Hướng dẫn tắt UXBuilder ở 1 số post type theme Flatsome

24/09/2024
1.6k
flatsome theme 1
Hướng dẫn Website

Bật UX Builder cho Custom post type trên theme Flatsome

24/09/2024
1.8k
Contact Form 7
Hướng dẫn Website

Chống spam cho plugin Contact Form 7

19/06/2024
1.6k
Contact Form 7
Hướng dẫn WordPress

Hướng dẫn cách truyền tiêu đề bài viết, sản phẩm vào Contact Form 7

19/06/2024
1.6k

Để lại một bình luận Hủy

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

No Result
View All Result

Recommended.

what is cpanel

Hướng dẫn sử dụng FileZilla kết nối SFTP

22/09/2021
1.5k
Git cPanel

Hướng dẫn dùng Git trên Hosting cPanel

01/02/2023
1.6k

Trending.

outlook là gì

Tạo rules trên Microsoft Outlook

29/05/2026
1.5k
outlook la gi cach cai dat va su dung outlook cho nguoi moi bat dau

Thay đổi thời gian cập nhật gửi nhận Email mới trên Outlook

29/05/2026
1.5k
cach tai toan bo email tren gmail ve may tinh de luu tru 4763

Cách tải toàn bộ email trên Gmail về máy tính để lưu trữ

10/04/2026
1.5k
Tên miền website là gì?

Vòng đời tên miền Việt Nam và Quốc Tế cập nhật năm 2026

07/04/2026
1.5k
binhluan

Cách ẩn comment trên Fanpage để tránh bị cướp khách hàng

09/12/2025
1.5k
Wiki Minh Duy Solutions

WIKI.MINHDUY.VN

Chuyên trang hướng dẫn sử dụng dịch vụ của Minh Duy Solutions

DMCA.com Protection Status

Danh mục

  • GSuite
  • aaPanel
  • Góc ICT
  • Thiết Kế Đồ Hoạ
  • SEO
  • Hướng dẫn WHMCS
  • Hướng dẫn WordPress
  • Email Zimbra
  • Hướng dẫn DirectAdmin
  • Hướng dẫn Hosting cPanel
  • Hướng dẫn Hosting
  • Office 365
  • Hướng dẫn Website
  • Hướng dẫn Linux
  • Hướng dẫn Hosting DirectAdmin
  • Google Work Space
  • Hướng dẫn Webmaster
  • Hướng dẫn máy chủ
  • Hướng dẫn Email Doanh Nghiệp
  • Hướng dẫn Tên miền
  • Hướng dẫn chung
  • Uncategorized

Thẻ

AFC apt-get update apt-get upgrade category chủ thể cPanel debian DirectAdmin email doanh nghiệp Environment Variables giải nén Google Workspace G Suite hosting ioncube khôi phục mật khẩu linux nginx nmap nodejs npm Office 365 OneDrive Outlook out of memory path Paypal phpmyadmin SMTP. GMail SSH sudo swap Symbolic Link tar tar.gz thông báo tên miền tên miền ubuntu user whois WooCommerce WordPress wordpress cơ bản wp rocket Zimbra
  • Về minhduy.vn
  • Đăng ký Hosting
  • Thiết kế Website
  • Khuyến mãi HOT

Copyright © Hướng dẫn Minh Duy Solutions

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
×
    No Result
    View All Result
    • Trang chủ
    • Hosting
      • Hướng dẫn Hosting cPanel
      • Hướng dẫn Hosting DirectAdmin
    • Tên miền
    • Website
      • Hướng dẫn WordPress
      • Hướng dẫn Webmaster
    • Email Doanh Nghiệp
      • Office 365
      • Google Work Space
      • Email Zimbra
    • VPS – Máy chủ
      • Hướng dẫn Linux
      • Hướng dẫn DirectAdmin
    • Hướng dẫn chung
    • Góc ICT

    Copyright © Hướng dẫn Minh Duy Solutions