// إضافة شريط الأخبار مع إمكانية التحكم في السرعة والنصوص والألوان
function add_news_ticker($speed = 40, $background_color = '#333', $text_color = 'white') {
?>
<div class="news-ticker" style="background-color: <?php echo $background_color; ?>;">
<ul>
<?php
// الحصول على آخر 3 مقالات
$recent_posts = wp_get_recent_posts( array(
'numberposts' => 4, // تحديد عدد المقالات
'post_status' => 'publish', // عرض المقالات المنشورة فقط
) );
foreach( $recent_posts as $post ) :
?>
<li><a href="<?php echo get_permalink( $post['ID'] ); ?>" style="color: <?php echo $text_color; ?>;"><?php echo esc_html( $post['post_title'] ); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<style>
.news-ticker {
padding: 10px;
font-size: 16px;
overflow: hidden;
white-space: nowrap;
width: 100%;
}
.news-ticker ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
animation: scroll-news <?php echo $speed; ?>s linear infinite; /* استخدام السرعة التي تم تمريرها */
}
.news-ticker li {
margin-right: 30px;
}
.news-ticker a {
text-decoration: none;
}
.news-ticker a:hover {
text-decoration: underline;
}
/* حركة الشريط */
@keyframes scroll-news {
0% {
transform: translateX(100%); /* يبدأ من جهة اليمين */
}
100% {
transform: translateX(-100%); /* ينتهي في جهة اليسار */
}
}
</style>
<?php
}
?>
<?php
// إضافة الشريط بعد الهيدر مباشرة لجميع الصفحات التي تحتوي على مقالات
if ( is_home() || is_single() || is_category() || is_archive() ) {
// يمكن تعديل سرعة الشريط (40 ثانية) ولون الخلفية (مثال: '#333') ولون النصوص (مثال: 'white')
add_news_ticker(40, '#333', 'white'); // يمكنك تعديل هذه القيم حسب الحاجة
}
// إضافة شريط الأخبار مع إمكانية التحكم في السرعة والنصوص والألوان
function add_news_ticker($speed = 40, $background_color = '#333', $text_color = 'white') {
?>
<div class="news-ticker" style="background-color: <?php echo $background_color; ?>;">
<ul>
<?php
// الحصول على آخر 3 مقالات
$recent_posts = wp_get_recent_posts( array(
'numberposts' => 3, // تحديد عدد المقالات
'post_status' => 'publish', // عرض المقالات المنشورة فقط
) );
foreach( $recent_posts as $post ) :
?>
<li><a href="<?php echo get_permalink( $post['ID'] ); ?>" style="color: <?php echo $text_color; ?>;"><?php echo esc_html( $post['post_title'] ); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<style>
.news-ticker {
padding: 10px;
font-size: 16px;
overflow: hidden;
white-space: nowrap;
width: 100%;
}
.news-ticker ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
animation: scroll-news <?php echo $speed; ?>s linear infinite; /* استخدام السرعة التي تم تمريرها */
}
.news-ticker li {
margin-right: 30px;
}
.news-ticker a {
text-decoration: none;
}
.news-ticker a:hover {
text-decoration: underline;
}
/* حركة الشريط */
@keyframes scroll-news {
0% {
transform: translateX(100%); /* يبدأ من جهة اليمين */
}
100% {
transform: translateX(-100%); /* ينتهي في جهة اليسار */
}
}
</style>
<?php
}
// إضافة الشريط في المقالات الفردية
if ( is_single() ) { // تأكد من عرض الشريط في المقالات الفردية فقط
add_news_ticker(40, '#333', 'white'); // يمكنك تعديل هذه القيم حسب الحاجة
}