كم يوم خميس سبت كل ايام الاسبوع حتي يوم 1-1-2026 النسخة الاولي
سأركز على جعل الكود بسيطًا وسهل التصحيح.
أعتذر للمشكلة المستمرة. سأقوم بكتابة كود منفصل ومستقل تماماً لشورت كود [day_of_week_counter] مع التأكد من صحته:
<?php
// ============================================================================
// DAY OF WEEK COUNTER - STANDALONE VERSION
// ============================================================================
// Register the shortcode
add_shortcode('day_of_week_counter', 'day_of_week_counter_handler');
function day_of_week_counter_handler($atts) {
// Set default attributes
$atts = shortcode_atts(array(
'date' => '',
'day' => 'Wednesday',
'language' => 'en',
'type' => 'until'
), $atts);
// Get attributes
$target_date = trim($atts['date']);
$day_name = trim($atts['day']);
$language = $atts['language'];
$type = $atts['type'];
// Validate required fields
if (empty($target_date)) {
return '<div style="color: red; padding: 20px; text-align: center; border: 2px solid red; border-radius: 10px;">❌ Error: Please provide a date using the "date" attribute. Example: [day_of_week_counter date="2026-05-21" day="Wednesday"]</div>';
}
if (empty($day_name)) {
return '<div style="color: red; padding: 20px; text-align: center; border: 2px solid red; border-radius: 10px;">❌ Error: Please provide a day name using the "day" attribute. Example: [day_of_week_counter date="2026-05-21" day="Wednesday"]</div>';
}
try {
// Create date objects
$target = new DateTime($target_date);
$today = new DateTime();
// Set time to midnight for accurate day comparison
$target->setTime(0, 0, 0);
$today->setTime(0, 0, 0);
// Check if date is valid
if (!$target) {
return '<div style="color: red; padding: 20px; text-align: center; border: 2px solid red; border-radius: 10px;">❌ Error: Invalid date format. Please use YYYY-MM-DD format.</div>';
}
// Validate day name
$valid_days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
$day_lower = strtolower($day_name);
if (!in_array($day_lower, $valid_days)) {
return '<div style="color: red; padding: 20px; text-align: center; border: 2px solid red; border-radius: 10px;">❌ Error: Invalid day name. Please use: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, or Sunday.</div>';
}
// Determine if target date is in past or future
$is_past = $target < $today;
// Validate type vs date direction
if ($type === 'until' && $is_past) {
return '<div style="color: red; padding: 20px; text-align: center; border: 2px solid red; border-radius: 10px;">❌ Error: For "until" calculations, the target date must be in the future. Your date is in the past.</div>';
}
if ($type === 'since' && !$is_past) {
return '<div style="color: red; padding: 20px; text-align: center; border: 2px solid red; border-radius: 10px;">❌ Error: For "since" calculations, the target date must be in the past. Your date is in the future.</div>';
}
// Calculate the number of specific weekdays
$day_count = 0;
$current = clone $today;
if ($type === 'until') {
// Count from today to target date (future)
while ($current <= $target) {
if (strtolower($current->format('l')) === $day_lower) {
$day_count++;
}
$current->modify('+1 day');
}
} else {
// Count from target date to today (past)
$current = clone $target;
while ($current <= $today) {
if (strtolower($current->format('l')) === $day_lower) {
$day_count++;
}
$current->modify('+1 day');
}
}
// Get date information for display
$target_day_of_week = $target->format('l');
$target_week_of_year = $target->format('W');
$target_year = $target->format('Y');
$target_month = $target->format('F');
$target_day_ordinal = $target->format('jS');
$full_target_date = $target->format('F j, Y');
// Calculate total time difference
$interval = $today->diff($target);
$total_days = $interval->days;
$total_weeks = floor($total_days / 7);
$total_months = $interval->y * 12 + $interval->m;
// Build display content based on language
if ($language === 'ar') {
// Arabic content
$arabic_days = [
'monday' => 'الاثنين',
'tuesday' => 'الثلاثاء',
'wednesday' => 'الأربعاء',
'thursday' => 'الخميس',
'friday' => 'الجمعة',
'saturday' => 'السبت',
'sunday' => 'الأحد'
];
$arabic_target_days = [
'monday' => 'الاثنين',
'tuesday' => 'الثلاثاء',
'wednesday' => 'الأربعاء',
'thursday' => 'الخميس',
'friday' => 'الجمعة',
'saturday' => 'السبت',
'sunday' => 'الأحد'
];
$day_ar = $arabic_days[$day_lower];
$target_day_ar = $arabic_target_days[strtolower($target_day_of_week)];
if ($type === 'until') {
$title = "كم {$day_ar} متبقي حتى {$target_month} {$target_day_ordinal}، {$target_year}؟";
$main_text = "هناك {$day_count} يوم {$day_ar} متبقي حتى {$full_target_date}";
$additional_info = "سيوافق {$full_target_date} يوم {$target_day_ar} وسيكون في الأسبوع {$target_week_of_year} من عام {$target_year}";
} else {
$title = "كم {$day_ar} مضى منذ {$target_month} {$target_day_ordinal}، {$target_year}؟";
$main_text = "لقد مضى {$day_count} يوم {$day_ar} منذ {$full_target_date}";
$additional_info = "وافق {$full_target_date} يوم {$target_day_ar} وكان في الأسبوع {$target_week_of_year} من عام {$target_year}";
}
} else {
// English content
if ($type === 'until') {
$title = "How many {$day_name}s until {$target_month} {$target_day_ordinal}, {$target_year}?";
$main_text = "There are {$day_count} {$day_name}s until {$full_target_date}";
$additional_info = "{$full_target_date} will be on a {$target_day_of_week} and will be in week {$target_week_of_year} of {$target_year}";
} else {
$title = "How many {$day_name}s since {$target_month} {$target_day_ordinal}, {$target_year}?";
$main_text = "There have been {$day_count} {$day_name}s since {$full_target_date}";
$additional_info = "{$full_target_date} was on a {$target_day_of_week} and was in week {$target_week_of_year} of {$target_year}";
}
}
// Build the output HTML
$output = "
<div style='
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
border-radius: 15px;
margin: 25px 0;
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
font-family: Arial, sans-serif;
'>
<!-- Main Title -->
<h1 style='
margin: 0 0 20px 0;
text-align: center;
font-size: 28px;
color: white;
'>
{$title}
</h1>
<!-- Main Content Box -->
<div style='
background: rgba(255,255,255,0.1);
padding: 25px;
border-radius: 12px;
margin-bottom: 25px;
text-align: center;
font-size: 18px;
line-height: 1.6;
border: 1px solid rgba(255,255,255,0.2);
'>
<p style='margin: 0 0 15px 0; font-size: 20px;'><strong>{$main_text}</strong></p>
<p style='margin: 0; opacity: 0.9;'>{$additional_info}</p>
</div>
<!-- Main Result Display -->
<div style='text-align: center; margin: 30px 0;'>
<div style='
display: inline-block;
background: rgba(255,255,255,0.2);
color: white;
padding: 40px 50px;
border-radius: 20px;
backdrop-filter: blur(10px);
border: 2px solid rgba(255,255,255,0.3);
'>
<div style='
font-size: 52px;
font-weight: bold;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
'>
" . number_format($day_count) . "
</div>
<div style='
font-size: 22px;
opacity: 0.9;
'>
" . ($language === 'ar' ? "أيام {$day_ar}" : "{$day_name}s") . "
</div>
</div>
</div>
<!-- Additional Statistics -->
<div style='
background: rgba(0,0,0,0.2);
padding: 25px;
border-radius: 12px;
margin-top: 20px;
'>
<h3 style='
margin: 0 0 20px 0;
text-align: center;
color: white;
font-size: 22px;
'>
" . ($language === 'ar' ? 'الإحصائيات الإضافية' : 'Additional Statistics') . "
</h3>
<div style='
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
font-size: 16px;
'>
<div style='
padding: 15px;
background: rgba(255,255,255,0.1);
border-radius: 8px;
text-align: center;
border: 1px solid rgba(255,255,255,0.1);
'>
<div style='
font-size: 28px;
font-weight: bold;
color: #ff6b6b;
margin-bottom: 5px;
'>
" . number_format($total_weeks) . "
</div>
<div style='font-size: 14px; opacity: 0.9;'>
" . ($language === 'ar' ? 'إجمالي الأسابيع' : 'Total Weeks') . "
</div>
</div>
<div style='
padding: 15px;
background: rgba(255,255,255,0.1);
border-radius: 8px;
text-align: center;
border: 1px solid rgba(255,255,255,0.1);
'>
<div style='
font-size: 28px;
font-weight: bold;
color: #4ecdc4;
margin-bottom: 5px;
'>
" . number_format($total_days) . "
</div>
<div style='font-size: 14px; opacity: 0.9;'>
" . ($language === 'ar' ? 'إجمالي الأيام' : 'Total Days') . "
</div>
</div>
<div style='
padding: 15px;
background: rgba(255,255,255,0.1);
border-radius: 8px;
text-align: center;
border: 1px solid rgba(255,255,255,0.1);
'>
<div style='
font-size: 28px;
font-weight: bold;
color: #45b7d1;
margin-bottom: 5px;
'>
" . number_format($total_months) . "
</div>
<div style='font-size: 14px; opacity: 0.9;'>
" . ($language === 'ar' ? 'إجمالي الأشهر' : 'Total Months') . "
</div>
</div>
</div>
</div>
<!-- Footer -->
<div style='
text-align: center;
margin-top: 25px;
font-size: 14px;
opacity: 0.8;
padding-top: 15px;
border-top: 1px solid rgba(255,255,255,0.2);
'>
<p>✨ " . ($language === 'ar' ? 'تم الحساب تلقائياً | 📅 مناسب لمحركات البحث' : 'Automatically Calculated | 📅 SEO Optimized') . " ✨</p>
</div>
</div>
";
return $output;
} catch (Exception $e) {
return '<div style="
background: #f8d7da;
color: #721c24;
padding: 25px;
border-radius: 10px;
margin: 20px 0;
border: 2px solid #f5c6cb;
text-align: center;
font-size: 16px;
">⚠️ ' . ($language === 'ar' ? 'خطأ في معالجة التاريخ: ' : 'Error processing date: ') . $e->getMessage() . '</div>';
}
}
// Ensure the shortcode is registered
add_action('init', function() {
if (!shortcode_exists('day_of_week_counter')) {
add_shortcode('day_of_week_counter', 'day_of_week_counter_handler');
}
});
// Debug function to test if shortcodes are working
add_shortcode('test_shortcode', function() {
return '✅ Shortcodes are working! If you see this, the shortcode system is functional.';
});
?>🧪 طريقة الاختبار خطوة بخطوة:
1. انسخ هذا الكود المنفرد وضعها في ملف functions.php
2. اختبر بهذا التسلسل:
أولاً: تحقق من عمل الشورت كود الأساسي
[test_shortcode]
إذا ظهرت ✅ فالشورت كود يعمل.
ثانياً: جرب الأمثلة التالية:
[day_of_week_counter date="2026-05-21" day="Wednesday" type="until" language="en"] [day_of_week_counter date="2020-01-01" day="Friday" type="since" language="en"] [day_of_week_counter date="2026-05-21" day="Monday" type="until" language="ar"]
3. إذا لم يعمل:
الخطوة 1: أضف هذا الكود للتحقق من الأخطاء:
// Add this temporarily to debug add_action('wp_footer', function() { if (shortcode_exists('day_of_week_counter')) { echo '<!-- ✅ day_of_week_counter shortcode is REGISTERED -->'; } else { echo '<!-- ❌ day_of_week_counter shortcode is NOT REGISTERED -->'; } });
الخطوة 2: تحقق من سجلات الأخطاء في ووردبريس.
📋 المعاملات المدعومة:
date(مطلوب): التاريخ المستهدف (صيغة: YYYY-MM-DD)day(مطلوب): يوم الأسبوع (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday)type:until(مستقبل) أوsince(ماضي) - الافتراضي:untillanguage:en(إنجليزي) أوar(عربي) - الافتراضي:en
🎯 ماذا يفعل هذا الكود:
يحسب عدد أيام الأسبوع المحددة بين اليوم والتاريخ المستهدف
يعرض نتيجة جميلة مع إحصائيات إضافية
يدعم اللغتين الإنجليزية والعربية
به تحقق من الأخطاء مع رسائل واضحة
تصميم متجاوب يعمل على جميع الأجهزة
جرب الكود الجديد وأخبرني بالنتيجة!
Comments
Post a Comment