Sportspress match scores pull | WordPress.org

[ad_1]

<?php
// Shortcode attributes
$atts = vc_map_get_attributes( $this->getShortcode(), $atts );
extract( $atts );

// Set class for marquee wrapper
$css_class=”marquee-wrapper” . vc_shortcode_custom_css_class( $css, ‘ ‘ ) . $this->getExtraClass( $el_class );

// Query SportPress events (matches)
$args = array(
‘post_type’ => ‘sp_event’,
‘post_status’ => array( ‘publish’, ‘future’ ),
‘posts_per_page’ => 10,
‘date_query’ => array(
array(
‘after’ => date(‘Y-m-d’, strtotime(‘-4 days’)), // 4 gün önce
‘before’ => date(‘Y-m-d’, strtotime(‘+4 days’)), // 4 gün sonrası
‘inclusive’ => true,
‘type’ => ‘DATE’,
),
),
);

$events_query = new WP_Query($args);
?>

<!– Matches Ticker –>
<div class=”<?php echo esc_attr($css_class); ?>”>
<div class=”container”>

<?php if ( ! empty( $title ) ) : ?>
<div class=”marquee-label”>
<?php echo esc_html( $title ); ?>
</div>
<?php endif; ?>

<?php if ( $events_query->have_posts() ) : ?>
<div class=”marquee” data-gap=”10″ data-duplicated=”false”>
<ul class=”posts posts–inline”>
<?php
$is_first_item = true; // İlk elemanı kontrol etmek için bir değişken oluşturuyoruz.
while ( $events_query->have_posts() ) : $events_query->the_post(); ?>
<?php
// Event ID’yi al
$event_id = get_the_ID();

// Takım bilgilerini alalım
$teams = sp_get_teams($event_id); // Takımların ID’lerini al

if (is_array($teams) && count($teams) > 1)
// Takım 1 ve Takım 2 bilgilerini al
$team1_id = $teams[0];
$team2_id = $teams[1];

// Takım isimlerini çek
$team1_name = get_the_title($team1_id);
$team2_name = get_the_title($team2_id);
else
// Eğer takımlar eksikse varsayılan “Bilinmiyor”
$team1_name = $team2_name=”Bilinmiyor”;

// Maç skoru alalım (ana sonuçları almak için sp_get_main_results kullanıyoruz)
$main_results = sp_get_main_results( $event_id );

// Skorları kontrol et
$home_score = isset($main_results[‘home’][‘goals’]) ? $main_results[‘home’][‘goals’] : null;
$away_score = isset($main_results[‘away’][‘goals’]) ? $main_results[‘away’][‘goals’] : null;

// Eğer skorlar boş ise, outcome verisini kontrol edelim
if ($home_score === null || $away_score === null)
// Outcome’ı alalım
$outcome = get_post_meta($event_id, ‘sp_outcome’, true);

// Outcome verisi varsa, sonucu “Galibiyet” “Mağlubiyet” veya “Beraberlik” olarak göster
if (!empty($outcome))
if ($outcome == ‘win’)
$home_score=”Galibiyet”;
$away_score=””;
elseif ($outcome == ‘loss’)
$home_score=”Mağlubiyet”;
$away_score=””;
elseif ($outcome == ‘draw’)
$home_score=”Beraberlik”;
$away_score=””;
else
$home_score = $away_score=”Bilinmiyor”;

else
$home_score = $away_score=”Bilinmiyor”;

// Maç saati UTC+3 olarak ayarlanacak
$match_time_utc = get_post_time( ‘H:i’, true, $event_id );
$match_time_utc3 = strtotime($match_time_utc) + (3 * 3600); // 3 saat ekleyerek UTC+3 yapıyoruz

// Formatlı saat UTC+3’e göre
$formatted_time = !empty($match_time_utc) ? date(‘H:i’, $match_time_utc3) : ‘Bilinmiyor’;

// Maç tarihi
$date_html = get_post_time( ‘Y-m-d’, false, $event_id );

// Maç tarihi varsa formatla, yoksa “Bilinmiyor” kullan
$formatted_date = !empty($date_html) ? date_i18n(‘j F Y’, strtotime($date_html)) : ‘Bilinmiyor’; // Türkçe tarih formatı

// Lig adı
$leagues = wp_get_post_terms($event_id, ‘sp_league’, array(‘fields’ => ‘names’));
$league_name = !empty($leagues) ? $leagues[0] : ‘Lig Bilinmiyor’;

// Maçın durumu: Yayınlanmış mı, gelecekte mi?
$post_status = get_post_status($event_id);

// Şu anki zamanı alalım
$current_time = current_time(‘Y-m-d H:i’);

// Geçmiş Maç Kontrolü: Oynamış maçları ve skorları ayıralım
if ($post_status == ‘publish’ && !empty($home_score) && !empty($away_score) && $date_html < date(‘Y-m-d’))
// Geçmiş maç ise sonuçları göster
$match_text = esc_html($formatted_date . ‘ – ‘ . $team1_name . ‘ ‘ . $home_score . ‘ – ‘ . $away_score . ‘ ‘ . $team2_name);

// Eğer maç bugünün tarihine sahip ve saat şu anki saatten daha sonraysa (yani oynanmamışsa)
elseif ($post_status == ‘publish’ && ($date_html == date(‘Y-m-d’)) && ($match_time_utc3 > strtotime($current_time)))
$match_text = esc_html($formatted_date . ‘ – ‘ . $team1_name . ‘ vs ‘ . $team2_name . ‘ – ‘ . $formatted_time);

// Eğer maç geçmişte oynanmışsa ve skoru eksikse, outcome ile durumu göster
elseif ( $post_status == ‘publish’ && ($date_html < date(‘Y-m-d’)) && (empty($home_score) || empty($away_score)) )
$outcome = get_post_meta($event_id, ‘sp_outcome’, true);
if ($outcome == ‘win’)
$home_score=”Galibiyet”;
$away_score=””;
elseif ($outcome == ‘loss’)
$home_score=”Mağlubiyet”;
$away_score=””;
elseif ($outcome == ‘draw’)
$home_score=”Beraberlik”;
$away_score=””;

$match_text = esc_html($formatted_date . ‘ – ‘ . $team1_name . ‘ ‘ . $home_score . ‘ – ‘ . $away_score . ‘ ‘ . $team2_name);

// Gelecek maçlar: Tarih ve saat ile göster
elseif ( $post_status == ‘future’ || $date_html > date(‘Y-m-d’) )
// Gelecek maçsa “vs” ve saat göster
$match_text = esc_html($formatted_date . ‘ – ‘ . $team1_name . ‘ vs ‘ . $team2_name . ‘ – ‘ . $formatted_time);

// Diğer durumlar için “Bilinmiyor”
else
$match_text = esc_html($formatted_date . ‘ – ‘ . $team1_name . ‘ vs ‘ . $team2_name . ‘ Bilinmiyor’);

// Separator ekleme işlemi
if ( !$is_first_item )
echo ‘<li class=”posts__item separator”>
$is_first_item = false; // İlk eleman artık işlendi.
?>

<!– Match item –>
<li class=”posts__item”>
<h6 class=”posts__title”>
<?php echo esc_html($league_name . ‘:’); ?> <!– League name –>
</h6>
<p class=”posts__text”>
<?php echo esc_html($match_text); ?> <!– Match details –>
</p>
</li>
<?php endwhile; ?>
</ul>
</div><!– .marquee –>
<?php wp_reset_postdata(); ?>
<?php endif; ?>

</div>
</div>
<!– Matches Ticker / End –>

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer