简体   繁体   English

如何向我的网站添加导航按钮

[英]How to add Navigation buttons to my website

I'm creating some 60+ HTML pages in my website. 我在网站上创建了60多个HTML页面。 I would like to have a previous and next navigation button/link in all pages. 我希望所有页面上都有上一个和下一个导航按钮/链接。 I know that we can do it manually by hard-coding on each page, but that is too mainstream. 我知道我们可以通过在每个页面上进行硬编码来手动完成此操作,但这太主流了。 I tried lots of pagination examples but I can't able achieve this. 我尝试了很多分页示例,但无法实现。 Can anyone suggest me how can I get this with some sort of script? 谁能建议我如何使用某种脚本来实现这一目标?

PS : Suggest with the combination of HTML + JS or anything frontend. PS:建议结合使用HTML + JS或任何前端。

Best, you can use MVC like CodeIgniter... It's need some hard-code at starting. 最好,您可以使用CodeIgniter之类的MVC ...开始时需要一些硬代码。 After that It's make easy. 之后,一切变得简单。 You can use Helpers, Library... 您可以使用助手,库...

Otherwise, 除此以外,

Put Page-nation in common file. 将Page-nation放在通用文件中。 Just Include that file in all other pages. 只需在其他所有页面中包含该文件即可。 It's make sense. 有道理。

These type of navigations are good when you use server side language like PHP or other. 当您使用服务器端语言(如PHP或其他语言)时,这些类型的导航非常有用。

Based on your question, below answer is not mainstream. 根据您的问题,以下答案不是主流。

Note :
I believe you give each and every page with hard coded is lot better
Time taken for hardcodding ~ Time taken for `not mainstream`
Choose it wisely..

Below are the few steps, i have explained, hope you understand it clearly 我已经解释了以下几个步骤,希望您能清楚理解

1. Initialize an array and store page names.
2. find the size of array
3. set current pagename in variable
4. find its location

5. If current location is greater than 0, then show prev button
6. If current location is lesser than total pages show next button

Code Starts here 代码从这里开始

<script>
var pages = new Array("pageOne.html", "pageTwo.html", "PageThree.html", "PageFour.html", "PageFive.html", "PageSix.html");
var totalPages = pages.length;

var curPageName = "PageThree.html"; // Enter your page name here
var getCurPageLocation = pages.indexOf(curPageName);

console.log("Total Pages : " + totalPages);
console.log("Current Page Name : " + curPageName);
console.log("Position of Page in Array : " + getCurPageLocation );


/* To find prev and next page code starts from here */
if (getCurPageLocation > 0) {
    var prevPageLocation = getCurPageLocation - 1;
    var prevPageName = pages[prevPageLocation];
    console.log("Prev Page Name : " + prevPageName);
}

if (getCurPageLocation < totalPages) {
    var nextPageLocation = getCurPageLocation + 1;
    var nextPageName = pages[nextPageLocation];
    console.log("Next Page Name : " + nextPageName);
}
/* To find prev and next page code ends here */


</script>

And If you need more navigation buttons like below 并且如果您需要更多导航按钮,如下所示

Prev 1 2 3 4 Next 上一页1 2 3 4下一页

Please try it yourself.. 请自己尝试。

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

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