繁体   English   中英

简单的网页导航“上一个下一个” PHP

[英]Simple Web Page Navigation 'Previous Next' Php

我有3(.php)个网站的文件/页面(在文件夹中),每个页面的底部都显示上一个/下一个链接。 上一个/下一个链接上的哪些php代码将帮助我导航至下一页。

例如:

可以说页面是Page1.php,Page2.php,Page3.php,而我目前正在使用Page2.php。

如果我想单击“上一个”链接,则希望显示Page1.php。

如果单击“下一步”,则希望显示Page3.php。

我相信这叫做“分页”吗?

以前

下一个


我不知道这是否可能。 我希望我已经清楚地描述了问题。

谢谢,

巴布斯多克

Here is the original code @Fred 

$images = "jars/"; # Location of small versions

$big    = "samp2/"; # Location of big versions (assumed to be a subdir of above)

$cols   = 2; # Number of columns to display

if ($handle = opendir($images)) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != ".." && $file != "samp2" && $file != "Thumbs.db") {
           $files[] = $file;
       }
   }
   closedir($handle);
}

foreach($files as $file)
{
$pc="Product Code:".substr($file,0,-4);

<a href=\"$images$big$file\" class=\"swap\"><img src=$images$file title=\"title\"
width=\"100\" height=\"100\">
$pc</a></li>";
}

假设您要始终保持通俗的命名约定(即pageX.php),那么以下内容就足够了。 (可能不是您理想的解决方案,但会给您一个想法。可以放入功能/进行更改等)

$strCurrentPage = basename($_SERVER['REQUEST_URI']);

$strPattern = '/\d+/';
preg_match($strPattern, $strCurrentPage, $strGetPageNumber); // extract numerical value

//set two new vars to same as page number, increment one and subtract one
$strNextPageNum = $strGetPageNumber[0];
$strPreviousPageNum = $strGetPageNumber[0];
$strNextPageNum++;
$strPreviousPageNum--;

//set full filename with new numbers
$strNextPage = 'page'.$strNextPageNum.'.php';
$strPreviousPage = 'page'.$strPreviousPageNum.'.php';


//if file is found then show link
//next page
if (file_exists($strNextPage))
  {
    echo '<a href="'.$strNextPage.'">Next Page</a>';
  }
else
  {
    echo "No more pages";
  }

//previous page
if (file_exists($strPreviousPage))
  {
    echo '<a href="'.$strPreviousPage.'">Previous Page</a>';
  }
else
  {
    echo "No previous pages";
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM