motayeb/footer.php
Kazem Alghasi c16648678d - install local Tailwind
- fix more problems
2026-09-23 00:32:16 +03:30

302 lines
16 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* فوتر سایت - مطابق با UI Kolli.html
*
* @package Motayeb
* @version 1.0.1
*
* تغییرات نسخه ۱.۰.۱:
* - guard کامل WooCommerce (بدون fatal error اگه غیرفعال باشه)
* - transient cache برای دسته‌بندی‌های فوتر
* - نمایش لینک فعال (active) در ناوبری موبایل بر اساس صفحه جاری
* - آیکون/رنگ دسته‌بندی از term meta (هماهنگ با front-page.php)
* - شماره تماس/ایمیل/آدرس از تنظیمات تم
* - aria-label روی همه بخش‌ها
* - Schema.org Footer Schema
* - دکمه Scroll to Top
* - رفع فضای اضافه در کلاس باتن موبایل
* - نماد اعتماد و ساماندهی به لینک‌های واقعی
*/
// تعیین آدرس فروشگاه — با guard ووکامرس
$footer_shop_url = ( function_exists( 'wc_get_page_id' ) && wc_get_page_id( 'shop' ) > 0 )
? get_permalink( wc_get_page_id( 'shop' ) )
: home_url( '/shop' );
// تشخیص صفحه جاری برای active state ناوبری موبایل
$current_url = home_url( add_query_arg( null, null ) );
$is_home = is_front_page() && is_home();
$is_shop_page = ( function_exists( 'is_shop' ) && is_shop() ) || ( function_exists( 'is_product_category' ) && is_product_category() );
$is_cart_or_checkout = ( function_exists( 'is_cart' ) && is_cart() ) || ( function_exists( 'is_checkout' ) && is_checkout() );
$is_account = ( function_exists( 'is_account_page' ) && is_account_page() );
// خواندن تنظیمات تم
$footer_phone = get_option( 'motayeb_contact_phone', '021-12345678' );
$footer_email = get_option( 'motayeb_contact_email', get_option( 'admin_email' ) );
$footer_address = get_option( 'motayeb_contact_address', 'تهران، ایران' );
$footer_instagram = get_option( 'motayeb_social_instagram', '' );
$footer_telegram = get_option( 'motayeb_social_telegram', '' );
$footer_twitter = get_option( 'motayeb_social_twitter', '' );
$samandehi_url = get_option( 'motayeb_samandehi_url', '' );
$enamad_url = get_option( 'motayeb_enamad_url', '' );
// لینک‌های خدمات مشتریان از صفحات وردپرس
$faq_page_id = get_option( 'motayeb_page_faq', 0 );
$return_page_id = get_option( 'motayeb_page_return', 0 );
$shipping_page_id = get_option( 'motayeb_page_shipping', 0 );
$privacy_page_id = get_option( 'motayeb_page_privacy', 0 );
$terms_page_id = get_option( 'motayeb_page_terms', 0 );
$about_page_id = get_option( 'motayeb_page_about', 0 );
$contact_page_id = get_option( 'motayeb_page_contact', 0 );
// تبدیل ID صفحه به URL (با fallback)
function motayeb_page_url( $page_id, $fallback = '#' ) {
if ( $page_id && get_post( $page_id ) ) {
return get_permalink( $page_id );
}
return $fallback;
}
// دسته‌بندی‌های فوتر با cache
$footer_cats_cache_key = 'motayeb_footer_categories';
$footer_cats = get_transient( $footer_cats_cache_key );
if ( false === $footer_cats ) {
$footer_cats = get_terms( array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
'parent' => 0,
'number' => 5,
'orderby' => 'count',
'order' => 'DESC',
) );
if ( ! is_wp_error( $footer_cats ) ) {
set_transient( $footer_cats_cache_key, $footer_cats, DAY_IN_SECONDS );
}
}
?>
</main><!-- پایان main -->
<!-- ===== SCROLL TO TOP ===== -->
<button id="scroll-to-top"
class="fixed bottom-20 right-4 md:bottom-6 md:right-6 z-40 w-11 h-11 bg-forest-500 dark:bg-forest-600 text-white rounded-full shadow-lg opacity-0 invisible transition-all hover:bg-forest-600 dark:hover:bg-forest-500"
aria-label="بازگشت به بالا">
<iconify-icon icon="lucide:arrow-up" width="20" class="mx-auto"></iconify-icon>
</button>
<!-- ===== FOOTER ===== -->
<footer class="bg-forest-500 dark:bg-forest-800 text-white" aria-label="فوتر سایت">
<div class="max-w-7xl mx-auto px-4 md:px-6 py-16">
<div class="grid grid-cols-2 md:grid-cols-4 gap-8 md:gap-12">
<!-- Brand -->
<div class="col-span-2 md:col-span-1">
<div class="flex items-center gap-2.5 mb-5">
<div class="w-10 h-10 bg-white/10 rounded-2xl flex items-center justify-center">
<iconify-icon icon="lucide:leaf" width="20" class="text-honey-300"></iconify-icon>
</div>
<div>
<span class="font-extrabold text-xl">مطیب</span>
<span class="block text-[9px] text-white/50 font-inter tracking-widest">MOTAYEB</span>
</div>
</div>
<p class="text-white/70 text-sm leading-relaxed mb-5">ارائه‌دهنده محصولات ارگانیک و طبیعی ایرانی با ضمانت اصالت و کیفیت.</p>
<?php if ( $footer_phone ) : ?>
<a href="tel:<?php echo esc_attr( preg_replace( '/[^0-9+]/', '', $footer_phone ) ); ?>"
class="flex items-center gap-2 text-sm text-white/70 hover:text-honey-300 transition mb-2"
dir="ltr">
<iconify-icon icon="lucide:phone" width="16" class="text-honey-300"></iconify-icon>
<span><?php echo esc_html( $footer_phone ); ?></span>
</a>
<?php endif; ?>
<?php if ( $footer_email ) : ?>
<a href="mailto:<?php echo esc_attr( $footer_email ); ?>"
class="flex items-center gap-2 text-sm text-white/70 hover:text-honey-300 transition mb-2"
dir="ltr">
<iconify-icon icon="lucide:mail" width="16" class="text-honey-300"></iconify-icon>
<span><?php echo esc_html( $footer_email ); ?></span>
</a>
<?php endif; ?>
<?php if ( $footer_address ) : ?>
<div class="flex items-start gap-2 text-sm text-white/70 mb-5">
<iconify-icon icon="lucide:map-pin" width="16" class="text-honey-300 mt-0.5 flex-shrink-0"></iconify-icon>
<span><?php echo esc_html( $footer_address ); ?></span>
</div>
<?php endif; ?>
<div class="flex gap-3">
<?php if ( $footer_instagram ) : ?>
<a href="<?php echo esc_url( $footer_instagram ); ?>" target="_blank" rel="noopener noreferrer" class="w-9 h-9 bg-white/10 rounded-lg flex items-center justify-center hover:bg-white/20 transition" aria-label="اینستاگرام">
<iconify-icon icon="lucide:instagram" width="18"></iconify-icon>
</a>
<?php endif; ?>
<?php if ( $footer_telegram ) : ?>
<a href="<?php echo esc_url( $footer_telegram ); ?>" target="_blank" rel="noopener noreferrer" class="w-9 h-9 bg-white/10 rounded-lg flex items-center justify-center hover:bg-white/20 transition" aria-label="تلگرام">
<iconify-icon icon="lucide:send" width="18"></iconify-icon>
</a>
<?php endif; ?>
<?php if ( $footer_twitter ) : ?>
<a href="<?php echo esc_url( $footer_twitter ); ?>" target="_blank" rel="noopener noreferrer" class="w-9 h-9 bg-white/10 rounded-lg flex items-center justify-center hover:bg-white/20 transition" aria-label="توییتر">
<iconify-icon icon="lucide:twitter" width="18"></iconify-icon>
</a>
<?php endif; ?>
</div>
</div>
<!-- Quick Links -->
<nav aria-label="دسترسی سریع">
<h4 class="font-bold mb-5">دسترسی سریع</h4>
<ul class="space-y-3 text-sm text-white/70">
<li><a href="<?php echo esc_url( home_url( '/' ) ); ?>" class="hover:text-honey-300 transition">صفحه اصلی</a></li>
<li><a href="<?php echo esc_url( $footer_shop_url ); ?>" class="hover:text-honey-300 transition">فروشگاه</a></li>
<li><a href="<?php echo esc_url( motayeb_page_url( $about_page_id, home_url( '/about' ) ) ); ?>" class="hover:text-honey-300 transition">درباره ما</a></li>
<li><a href="<?php echo esc_url( home_url( '/blog' ) ); ?>" class="hover:text-honey-300 transition">مجله سلامت</a></li>
<li><a href="<?php echo esc_url( motayeb_page_url( $contact_page_id, home_url( '/contact' ) ) ); ?>" class="hover:text-honey-300 transition">تماس با ما</a></li>
</ul>
</nav>
<!-- Categories -->
<nav aria-label="دسته‌بندی محصولات">
<h4 class="font-bold mb-5">دسته‌بندی‌ها</h4>
<ul class="space-y-3 text-sm text-white/70">
<?php
if ( ! empty( $footer_cats ) && ! is_wp_error( $footer_cats ) ) {
foreach ( $footer_cats as $cat ) {
echo '<li><a href="' . esc_url( get_term_link( $cat ) ) . '" class="hover:text-honey-300 transition">' . esc_html( $cat->name ) . '</a></li>';
}
} else {
echo '<li><a href="' . esc_url( $footer_shop_url ) . '" class="hover:text-honey-300 transition">همه محصولات</a></li>';
}
?>
</ul>
</nav>
<!-- Customer Service -->
<nav aria-label="خدمات مشتریان">
<h4 class="font-bold mb-5">خدمات مشتریان</h4>
<ul class="space-y-3 text-sm text-white/70">
<li><a href="<?php echo esc_url( motayeb_page_url( $faq_page_id ) ); ?>" class="hover:text-honey-300 transition">سوالات متداول</a></li>
<li><a href="<?php echo esc_url( motayeb_page_url( $return_page_id ) ); ?>" class="hover:text-honey-300 transition">شرایط بازگشت</a></li>
<li><a href="<?php echo esc_url( motayeb_page_url( $shipping_page_id ) ); ?>" class="hover:text-honey-300 transition">نحوه ارسال</a></li>
<li><a href="<?php echo esc_url( motayeb_page_url( $privacy_page_id ) ); ?>" class="hover:text-honey-300 transition">حریم خصوصی</a></li>
<li><a href="<?php echo esc_url( motayeb_page_url( $terms_page_id ) ); ?>" class="hover:text-honey-300 transition">قوانین و مقررات</a></li>
</ul>
</nav>
</div>
</div>
<!-- Bottom Bar -->
<div class="border-t border-white/10">
<div class="max-w-7xl mx-auto px-4 md:px-6 py-5 flex flex-col md:flex-row items-center justify-between gap-4">
<p class="text-xs text-white/50">© <?php echo esc_html( date_i18n( 'Y' ) ); ?> مطیب. تمامی حقوق محفوظ است.</p>
<div class="flex items-center gap-4">
<?php if ( $enamad_url ) : ?>
<a href="<?php echo esc_url( $enamad_url ); ?>" target="_blank" rel="noopener noreferrer"
class="flex items-center gap-2 px-3 py-1.5 bg-white/10 rounded-lg text-xs hover:bg-white/20 transition">
<iconify-icon icon="lucide:shield-check" width="14" class="text-honey-300"></iconify-icon>
<span>نماد اعتماد</span>
</a>
<?php endif; ?>
<?php if ( $samandehi_url ) : ?>
<a href="<?php echo esc_url( $samandehi_url ); ?>" target="_blank" rel="noopener noreferrer"
class="flex items-center gap-2 px-3 py-1.5 bg-white/10 rounded-lg text-xs hover:bg-white/20 transition">
<iconify-icon icon="lucide:badge-check" width="14" class="text-honey-300"></iconify-icon>
<span>ساماندهی</span>
</a>
<?php endif; ?>
</div>
</div>
</div>
</footer>
<!-- ===== MOBILE BOTTOM NAV ===== -->
<nav class="md:hidden fixed bottom-0 left-0 right-0 z-40 bg-white/90 dark:bg-dark-card/90 backdrop-blur-xl border-t border-cream-200 dark:border-dark-border bottom-nav"
aria-label="ناوبری موبایل">
<div class="flex items-center justify-around py-2">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>"
class="flex flex-col items-center gap-0.5 px-3 py-1.5 <?php echo $is_home ? 'text-forest-500 dark:text-forest-300' : 'text-cream-500 dark:text-dark-muted'; ?>"
aria-label="خانه">
<iconify-icon icon="lucide:home" width="22"></iconify-icon>
<span class="text-[10px] font-medium">خانه</span>
</a>
<a href="<?php echo esc_url( $footer_shop_url ); ?>"
class="flex flex-col items-center gap-0.5 px-3 py-1.5 <?php echo $is_shop_page ? 'text-forest-500 dark:text-forest-300' : 'text-cream-500 dark:text-dark-muted'; ?>"
aria-label="فروشگاه">
<iconify-icon icon="lucide:grid-3x3" width="22"></iconify-icon>
<span class="text-[10px] font-medium">دسته‌بندی</span>
</a>
<button onclick="openCart()"
class="relative flex flex-col items-center gap-0.5 px-3 py-1.5 <?php echo $is_cart_or_checkout ? 'text-forest-500 dark:text-forest-300' : 'text-cream-500 dark:text-dark-muted'; ?>"
aria-label="سبد خرید">
<iconify-icon icon="lucide:shopping-bag" width="22"></iconify-icon>
<span class="text-[10px] font-medium">سبد خرید</span>
<span id="mobile-cart-count" class="absolute -top-0.5 right-1 w-4 h-4 bg-honey-400 text-white text-[9px] font-bold rounded-full flex items-center justify-center hidden">0</span>
</button>
<button onclick="openMobileMenu()"
class="flex flex-col items-center gap-0.5 px-3 py-1.5 <?php echo $is_account ? 'text-forest-500 dark:text-forest-300' : 'text-cream-500 dark:text-dark-muted'; ?>"
aria-label="حساب کاربری">
<iconify-icon icon="lucide:user" width="22"></iconify-icon>
<span class="text-[10px] font-medium">حساب من</span>
</button>
</div>
</nav>
<!-- Spacer for mobile nav -->
<div class="md:hidden h-16"></div>
<?php
// Schema.org Footer Schema
$footer_schema = array(
'@context' => 'https://schema.org',
'@type' => 'WPFooter',
'url' => home_url( '/' ),
'name' => get_bloginfo( 'name' ),
'description' => get_bloginfo( 'description' ),
'publisher' => array(
'@type' => 'Organization',
'name' => get_bloginfo( 'name' ),
'url' => home_url( '/' ),
),
);
if ( $footer_email ) {
$footer_schema['publisher']['email'] = $footer_email;
}
if ( $footer_phone ) {
$footer_schema['publisher']['telephone'] = $footer_phone;
}
if ( $footer_address ) {
$footer_schema['publisher']['address'] = array(
'@type' => 'PostalAddress',
'streetAddress' => $footer_address,
'addressCountry'=> 'IR',
);
}
echo '<script type="application/ld+json">' . wp_json_encode( $footer_schema ) . '</script>';
?>
<!-- اسکریپت دکمه Scroll to Top -->
<script>
(function() {
var btn = document.getElementById('scroll-to-top');
if (!btn) return;
window.addEventListener('scroll', function() {
if (window.scrollY > 400) {
btn.classList.remove('opacity-0', 'invisible');
btn.classList.add('opacity-100', 'visible');
} else {
btn.classList.add('opacity-0', 'invisible');
btn.classList.remove('opacity-100', 'visible');
}
}, { passive: true });
btn.addEventListener('click', function() {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
})();
</script>
<?php wp_footer(); ?>
</body>
</html>