Files
ITStudioMainSite/themes/ITStudioMainSite/index.php
T

160 lines
8.2 KiB
PHP

<?php get_header(); ?>
<main class="site-main home-landing">
<?php
$site_content = itstudio_get_site_content_settings();
$announcement_archive_url = get_post_type_archive_link('announcement');
if (!$announcement_archive_url) {
$announcement_archive_url = home_url('/announcements');
}
$club_news_url = get_post_type_archive_link('news');
if (!$club_news_url) {
$club_news_url = home_url('/news');
}
?>
<section class="landing-hero">
<canvas class="landing-hero-canvas" aria-hidden="true"></canvas>
<div class="container">
<div class="landing-hero-content">
<h1 class="landing-hero-title" data-cn="爱特工作室" data-en="IT STUDIO"></h1>
<p class="landing-hero-subtitle" data-cn="中国海洋大学信息技术与工程实践团队" data-en="Technology and Engineering Practice Team at OUC"></p>
<a class="landing-hero-btn" href="<?php echo esc_url(home_url('/about')); ?>" data-cn="了解更多" data-en="Learn More"></a>
</div>
</div>
</section>
<section class="services-section">
<div class="container">
<div class="services-provided">
<h2 data-cn="@ 服务提供" data-en="@ Services"></h2>
<div class="services-grid-box">
<?php foreach (array_slice((array) ($site_content['homepage_services'] ?? array()), 0, 8) as $service) : ?>
<?php
$name_cn = trim((string) ($service['name_cn'] ?? ''));
$name_en = trim((string) ($service['name_en'] ?? ''));
if ($name_cn === '' && $name_en === '') {
continue;
}
if ($name_cn === '') {
$name_cn = $name_en;
}
if ($name_en === '') {
$name_en = $name_cn;
}
$image_id = absint($service['image_id'] ?? 0);
$image_url = $image_id > 0 ? wp_get_attachment_image_url($image_id, 'medium') : '';
if (!$image_url && $image_id > 0) {
$image_url = wp_get_attachment_url($image_id);
}
if (!is_string($image_url) || $image_url === '') {
$image_url = get_template_directory_uri() . '/resources/it_logo_2024.svg';
}
?>
<div class="service-item">
<div class="service-icon">
<img class="service-image" src="<?php echo esc_url($image_url); ?>" alt="" aria-hidden="true">
</div>
<span data-cn="<?php echo esc_attr($name_cn); ?>" data-en="<?php echo esc_attr($name_en); ?>"></span>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</section>
<section class="landing-updates">
<div class="container">
<div class="landing-updates-grid">
<article class="landing-feed-box">
<header class="landing-feed-head">
<h2 data-cn="@ 公告通知" data-en="@ Announcements"></h2>
<a href="<?php echo esc_url($announcement_archive_url); ?>" data-cn="更多" data-en="More"></a>
</header>
<ul class="landing-feed">
<?php
$announcements = new WP_Query(array(
'post_type' => 'announcement',
'post_status' => 'publish',
'posts_per_page' => 5,
'orderby' => 'date',
'order' => 'DESC',
'ignore_sticky_posts' => true,
'no_found_rows' => true
));
if ($announcements->have_posts()) :
while ($announcements->have_posts()) : $announcements->the_post();
$announcement_excerpt = get_the_excerpt();
if ('' === trim($announcement_excerpt)) {
$announcement_excerpt = wp_trim_words(wp_strip_all_tags(get_the_content()), 40, '...');
}
?>
<li class="landing-feed-item">
<h3 class="landing-feed-title">
<a class="landing-feed-link" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h3>
<div class="landing-feed-meta">
<span class="landing-feed-author"><?php echo esc_html(get_the_author()); ?></span>
<time datetime="<?php echo esc_attr(get_the_date('c')); ?>"><?php echo esc_html(get_the_date('Y-m-d H:i')); ?></time>
</div>
<p class="landing-feed-excerpt"><?php echo esc_html($announcement_excerpt); ?></p>
</li>
<?php
endwhile;
wp_reset_postdata();
else :
?>
<li class="landing-feed-empty" data-cn="暂无公告" data-en="No announcements found."></li>
<?php endif; ?>
</ul>
</article>
<article class="landing-feed-box">
<header class="landing-feed-head">
<h2 data-cn="@ 社团新闻" data-en="@ Club News"></h2>
<a href="<?php echo esc_url($club_news_url); ?>" data-cn="更多" data-en="More"></a>
</header>
<ul class="landing-feed">
<?php
$blogs = new WP_Query(array(
'post_type' => 'news',
'post_status' => 'publish',
'posts_per_page' => 5,
'orderby' => 'date',
'order' => 'DESC',
'ignore_sticky_posts' => true,
'no_found_rows' => true
));
if ($blogs->have_posts()) :
while ($blogs->have_posts()) : $blogs->the_post();
$blog_excerpt = get_the_excerpt();
if ('' === trim($blog_excerpt)) {
$blog_excerpt = wp_trim_words(wp_strip_all_tags(get_the_content()), 40, '...');
}
?>
<li class="landing-feed-item">
<h3 class="landing-feed-title">
<a class="landing-feed-link" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h3>
<div class="landing-feed-meta">
<span class="landing-feed-author"><?php echo esc_html(get_the_author()); ?></span>
<time datetime="<?php echo esc_attr(get_the_date('c')); ?>"><?php echo esc_html(get_the_date('Y-m-d H:i')); ?></time>
</div>
<p class="landing-feed-excerpt"><?php echo esc_html($blog_excerpt); ?></p>
</li>
<?php
endwhile;
wp_reset_postdata();
else :
?>
<li class="landing-feed-empty" data-cn="暂无社团新闻" data-en="No club news found."></li>
<?php endif; ?>
</ul>
</article>
</div>
</div>
</section>
</main>
<?php get_footer(); ?>