我有 100 个 php 页面,而且全都是静态页面。我希望在每个页脚中都有下一页/上一页链接,该链接应该自动工作,而不是手动设置。所有页面都将具有“组件/按钮”、“组件/工具提示”、“设计/令牌”和“开始使用”等 URL。
与页脚中的碳设计系统相同。
我希望有一种更简单的方法来自动链接每个组件页面。我尝试了一些 jQuery 但没有得到所需的结果。
页脚导航.php:
<?php
// Array of pages in the order they should appear
$pages = [
'/test.php',
'/files/file1.php',
'/files/file2.php'
];
$currentUrl = $_SERVER['REQUEST_URI'];
$currentIndex = array_search($currentUrl, $pages);
$prevIndex = $currentIndex > 0 ? $currentIndex - 1 : null;
$nextIndex = $currentIndex < count($pages) - 1 ? $currentIndex + 1 : null;
$prevUrl = $prevIndex !== null ? $pages[$prevIndex] : '#';
$nextUrl = $nextIndex !== null ? $pages[$nextIndex] : '#';
?>
<footer>
<?php if($prevIndex !== null): ?>
<a href="<?php echo $prevUrl; ?>">Previous</a>
<?php endif; ?>
<?php if($nextIndex !== null): ?>
<a href="<?php echo $nextUrl; ?>">Next</a>
<?php endif; ?>
</footer>
要将导航添加到每个页面,请将以下内容放在页脚中:
<?php include 'footer-navigation.php'; ?>
确保与 footer-navigation.php 不在同一目录中的页面路径正确。