![](/img/trans.png)
[英]Jquery pagination plugin - Next/Previous pagination links to show next/previous full group of page numbers
[英]Creating Next/Previous pagination links
我正在一个投资组合站点上工作,并且所有项目都处于阵列中,我创建了一个项目模板页面,该页面使用GET变量设置当前项目并将适当的内容加载到页面中。 我正在尝试在底部添加指向下一个和上一个项目的链接,但无法找出编写链接的正确方法
这是数组的样子:
$projects = array();
$projects["Beeston-Residence"] = array(
"name" => "Beeston House",
"heroClass" => "hero-beeston",
"mainImg" => BASE_URL ."images/beeston_main.jpg",
"previewImg" => BASE_URL ."images/beeston_preview.jpg",
"year" => "2014",
"yearClass" => "twenty14",
"location" => "Brisbane, Australia",
"photographer" => "Rachel Cruz",
"detailOne" => BASE_URL ."images/beeston_detail1.jpg",
"detailTwo" => BASE_URL ."images/beeston_detail2.jpg",
"detailThree" => BASE_URL ."images/beeston_detail3.jpg",
"detailFour" => BASE_URL ."images/beeston_detail4.jpg",
"description" => "lorem ipsum and shit",
"detailOneSum" => "lorem ipsum detail 1",
"detailTwoSum" => "lorem ipsum detail 2",
"detailThreeSum" => "lorem ipsum detail 3",
"detailFourSum" => "Lorem ipsum detail 4",
"materials" => array("matOne","matTwo","matThree"),
"materialImg" => array(BASE_URL ."images/beeston_mat1.jpg",BASE_URL ."images/beeston_mat2.jpg",BASE_URL ."images/beeston_mat3.jpg"),
"testamonialImg" => BASE_URL ."images/client.jpg",
"testamonial" => "Cabin Is Great!"
);
$projects["Book-Tower-Residence"] = array(
"name" => "Book Tower House",
"heroClass" => "hero-bookTower",
"mainImg" => BASE_URL ."images/bookTower_main.jpg",
"previewImg" => BASE_URL ."images/bookTower_preview.jpg",
"year" => "2012",
"yearClass" => "twenty12",
"location" => "London, United Kingdom",
"photographer" => "Rachel Cruz",
"detailOne" => BASE_URL ."images/bookTower_detail1.jpg",
"detailTwo" => BASE_URL ."images/bookTower_detail2.jpg",
"detailThree" => BASE_URL ."images/bookTower_detail3.jpg",
"detailFour" => BASE_URL ."images/bookTower_detail4.jpg",
"description" => "lorem ipsum and shit",
"detailOneSum" => "lorem ipsum",
"detailTwoSum" => "lorem ipsum",
"detailThreeSum" => "lorem ipsum",
"detailFourSum" => "Lorem ipsum",
"materials" => array("matOne","matTwo","matThree"),
"materialImg" => array(BASE_URL ."images/bookTower_mat1.jpg",BASE_URL ."images/bookTower_mat2.jpg",BASE_URL ."images/bookTower_mat3.jpg"),
"testamonialImg" => BASE_URL ."images/client.jpg",
"testamonial" => "Cabin Is Great!"
);
$projects["1917-Bungalow"] = array(
"name" => "1917 Bungalow",
"heroClass" => "hero-bungalow",
"mainImg" => BASE_URL ."images/bungalow_main.jpg",
"previewImg" => BASE_URL ."images/bungalow_preview.jpg",
"year" => "2013",
"yearClass" => "twenty13",
"location" => "Autstin, Texas",
"photographer" => "Rachel Cruz",
"detailOne" => BASE_URL ."images/bungalow_detail1.jpg",
"detailTwo" => BASE_URL ."images/bungalow_detail2.jpg",
"detailThree" => BASE_URL ."images/bungalow_detail3.jpg",
"detailFour" => BASE_URL ."images/bungalow_detail4.jpg",
"description" => "lorem ipsum and shit",
"detailOneSum" => "lorem ipsum",
"detailTwoSum" => "lorem ipsum",
"detailThreeSum" => "lorem ipsum",
"detailFourSum" => "Lorem ipsum",
"materials" => array("matOne","matTwo","matThree"),
"materialImg" => array(BASE_URL ."images/bungalow_mat1.jpg",BASE_URL ."images/bungalow_mat2.jpg",BASE_URL ."images/bungalow_mat3.jpg"),
"testamonialImg" => BASE_URL ."images/client.jpg",
"testamonial" => "Cabin Is Great!"
);
等等...阵列共有15个项目
项目模板过滤到的项目设置如下:
<?php
require_once("../includes/config.php");
require_once(ROOT_PATH . "includes/projectInfo.php");
$project_id = $_GET["id"];
$project = $projects[$project_id];
include (ROOT_PATH . "includes/header-project-page.php");
?>
<section class="l-col-group project-intro">
<h2 class="project-title"><?php echo $project["name"]; ?> </h2>
<aside class="project-info">
<ul class="project-brief">
<li class="pb-heading">STATUS </li>
<li class="pb-info">Complete <?php echo $project["year"];?></li>
<li class="pb-heading">LOCATION</li>
<li class="pb-info"><?php echo $project["location"];?></li>
<li class="pb-heading">PHOTOGRAPHER</li>
<li class="pb-info"><?php echo $project["photographer"];?></li>
</ul>
</aside>
<p class="project-summary">
<?php echo $project["description"];?>
</p>
</section>
<section>
<figure class="l-col-group">
<figcaption class= "left">
<h3>VISION</h3>
<p><?php echo $project["detailOneSum"];?></p>
</figcaption>
<img class="project-detail-img right" src="<?php echo $project["detailOne"];?>" alt="">
</figure>
<figure class="l-col-group">
<figcaption class="right">
<h3>DESIGN</h3>
<p><?php echo $project["detailTwoSum"];?></p>
</figcaption>
<img class="project-detail-img left" src="<?php echo $project["detailTwo"];?>" alt="">
</figure>
<figure class="l-col-group left">
<figcaption class="left">
<h3>DEVELOPMENT</h3>
<p><?php echo $project["detailThreeSum"];?></p>
</figcaption>
<img class="project-detail-img right" src="<?php echo $project["detailThree"];?>" alt="">
</figure>
<figure class="l-col-group">
<figcaption class="right">
<h3>TEAM</h3>
<p><?php echo $project["detailFourSum"];?></p>
</figcaption>
<img class="project-detail-img left" src="<?php echo $project["detailFour"];?>" alt="">
</figure>
</section>
<section class="testamonial">
<img class="testamonial-image" src="<?php echo BASE_URL; ?>images/testamonial.png" alt="testamonial">
<h3 class="testamonial-client">DAVID WALSH</h3>
<p class="testamonial-quote">Cabin surpassed went above and beyond my wildest dreams! Customer service at its best.</p>
</section>
include (ROOT_PATH . "includes/contact.php");
include (ROOT_PATH . "includes/footer.php");
?>
我很幸运通过使用以下命令来检索数组中的当前项目位置:
<?php $key = array_search($project, $projects);
$offset = array_search($key, array_keys($projects));
$next = $offset + 1;
$prev = $offset - 1;
?>
但是在弄清楚如何使用此信息创建到数组中下一个项目的链接时遇到了麻烦
我正在尝试类似的事情,但不知道该把什么作为链接
<?php if ($prev > 0): ?>
<a style ="color:black" href="">Previous</a>
<?php endif; ?>
<?php
预先感谢您的帮助。 干杯。
传递索引而不传递id可能更好,更简单:
// get project id
$lst_ids = array_keys($project);
$i = !empty($_GET["i"]) ? $_GET["i"] : 0;
$project_id = $lst_ids[$i];
// show previous and next links, as applicable
$l = count($projects); // should give 15
$html = '';
if ($i) {
$i_prev = $i - 1;
$label = "← Previous";
$html .= "<a href='?i=$i_prev'>$label</a>";
}
if ($i < ($l - 1)) {
$i_next = $i + 1;
$label = "Next →";
$html .= " <a href='?i=$i_next'>$label</a>";
}
echo $html;
或者,如果您想传递ID:
$l = count($projects); // should give 15
$lst_ids = array_keys($project);
$project_id = !empty($_GET["id"]) ? $_GET["id"] : NULL;
$index = $project_id ? array_search($project_id, $lst_ids) : 0;
$html = '';
if ($index) {
$id_prev = $lst_ids[$index - 1];
$label = "← Previous";
$html .= "<a href='?id=$id_prev'>$label</a>";
}
if ($index < ($l - 1)) {
$id_next = $lst_ids[$index + 1];
$label = "Next →";
$html .= " <a href='?id=$id_next'>$label</a>";
}
echo $html;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.