本学のSDGsへの取り組み
', $block)[0] . '';
$timestamp = 0;
// 日付抽出
if (preg_match('/newsDate\[(.*?)\]/', $li_content, $d_match)) {
$timestamp = strtotime(trim($d_match[1]));
}
elseif (preg_match('/(\d{4})\.(\d{2})\.(\d{2})/', $li_content, $d_match)) {
$timestamp = strtotime($d_match[1].'-'.$d_match[2].'-'.$d_match[3]);
}
if ($timestamp > 0) {
$all_items[] = [
'time' => $timestamp,
'html' => $li_content
];
}
}
}
// 日付順に並び替え
usort($all_items, function($a, $b) {
if ($a['time'] == $b['time']) {
return 0;
}
return ($b['time'] > $a['time']) ? 1 : -1;
});
// ページング定義
$total_count = count($all_items);
$total_pages = ceil($total_count / $items_per_page);
$offset = ($current_page - 1) * $items_per_page;
$display_items = array_slice($all_items, $offset, $items_per_page);
// 表示処理
echo "\n";
echo '';
if (count($display_items) > 0) {
foreach ($display_items as $item) {
echo $item['html'];
}
} else {
echo '- 該当する記事がありません。
';
}
echo '
';
// ページャー出力
if ($total_pages > 1) {
echo '';
$prev = $current_page - 1;
$next = $current_page + 1;
// 最初へ
if ($current_page > 1) {
echo '- <<
';
echo '- <
';
} else {
echo '- <<
';
echo '- <
';
}
// ページ数字
$range = 2; // 現在のページの前後に表示する数
$start = max(1, $current_page - $range);
$end = min($total_pages, $current_page + $range);
// 表示数が5に満たない場合の調整(端に寄った時に反対側を伸ばす)
if ($end - $start < 4) {
if ($start == 1) {
$end = min($total_pages, $start + 4);
} elseif ($end == $total_pages) {
$start = max(1, $end - 4);
}
}
for ($i = $start; $i <= $end; $i++) {
if ($i == $current_page) {
echo '- '.$i.'
';
} else {
echo '- '.$i.'
';
}
}
// 次へ、最後へ
if ($current_page < $total_pages) {
echo '- >
';
echo '- >>
';
} else {
echo '- >
';
echo '- >>
';
}
echo '
';
}
?>