Article page links with HTML?

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

leech9021

Thread Starter
Joined
Jun 29, 2007
Messages
4
I am currently in the process of building a website for my dad and his business. He wrote up a big long article and wants to break it down into sub-pages. At the bottom of all these pages I wanted to have a php include script with just a simple something like, "Pages: 1, 2, 3, 4," etc.

My question is, is it possible to make it so that when it is on page 1, to have the hyperlink removed, but then put back when you move to page 2. Keep in mind I am going to make a little php file for this and just have a little phpinclude on the bottom of each site. I know if I just used simple HTML it would be very easy to do this.

Maybe is there some sort of "if" function? Like if I am on the first page, remove the hyperlink of the "1" at the bottom, and put it back for all the other pages.
 
Joined
Nov 22, 2003
Messages
6,052
lets say you're doing something like index.php?page=2 to seperate pages, with a total of 5 pages(6 pages would make $i < 6 into $i < 7, etc), you would use something along these lines, it will still show every number every time, but it won't make it a hyperlink if its the page you are on.

Code:
for($i = 1; $i < 6; $i++){
     if($_GET['page'] == $i)
          echo $i.", ";
     else
          echo "<a href=\"index.php?page=".($i + 1)."\">".$i."</a>, ";
     }
 

leech9021

Thread Starter
Joined
Jun 29, 2007
Messages
4
Thanks for responding. With this code, the only thing I don't understand is what to name all the pages. Could you give me an example of what names would be for the first couple pages?
Thanks
 

MMJ

Guest
Joined
Oct 15, 2006
Messages
3,625
Big-K said:
lets say you're doing something like index.php?page=2 to seperate pages, with a total of 5 pages(6 pages would make $i < 6 into $i < 7, etc), you would use something along these lines, it will still show every number every time, but it won't make it a hyperlink if its the page you are on.

Code:
for($i = 1; $i < 6; $i++){
     if($_GET['page'] == $i)
          echo $i.", ";
     else
          echo "<a href=\"index.php?page=".($i + 1)."\">".$i."</a>, ";
     }
Wouldn't exactly work.

Lets say you are on page 3. clicking on page 4 would lead to 5 because you say $i + 1. No point in that.

@leech9021: one way would would be to name part 1 of the article "1.html", part 2 "2.html", etc.

Then use this code:
PHP:
<?php
//FIRST PART OF CODE
if ($_GET['page'] > 0 && $_GET['page'] < 6)
	include("$_GET[page].html");
//SECOND PART OF CODE
for($i = 1; $i < 6; $i++)
{
	if($_GET['page'] == $i)
		echo "$i, ";
	else
		echo "<a href=\"?page=$i\">$i</a>, ";
}
?>
Put the first part of code wherever you want the html file to be.

Put the second part of code where you want the links to show.

You could do a NEXT PAGE & PREVIOUS PAGE like this:

<a href="?page=<?= $_GET['page']-1 ?>">Previous page</a>

AND

<a href="?page=<?= $_GET['page']+1?>">Next page</a>

However if you want to do something like that you should do some validation first.
 

leech9021

Thread Starter
Joined
Jun 29, 2007
Messages
4
So, I'd rather name them something other than 1.html, 2.html, etc, because there are going to be more than one articles that I am going to be applying this to.

For example, would it be possible to name them intro1.html, intro2.html, etc.? And if this is possible, how would it affect the code you posted? For this first example there are going to be 5 pages.

Also, when you say put the first part of the code wherever I want the html file to be, what exactly do you mean by that? Can you be a bit more specific on where to put the first part?

I'm still fairly new to all this, thanks for your help and patience.
 

MMJ

Guest
Joined
Oct 15, 2006
Messages
3,625
1. Okay, change the code to include("intro$_GET[page].html");

2. Lets say the page intro1.html has inside of it "text text text". so call the include function wherever you want the text to be. for example if you wanted the page title to be "text text text" then do this:
<html>
<head>
<title><? include("intro1.html")?></title>
</head>
<body>
body content
</body>
</html>

See what I mean? play with it and you should get the hang of it. :)
 

leech9021

Thread Starter
Joined
Jun 29, 2007
Messages
4
ok, I get how the basic include function works, what I was wondering about was more the implementation of this certain script.
My intro1.php, intro2.php, etc files are going to be the different pages of the articles.
In these files, somewhere near the bottom (wherever I wanted to place the Page 1, Page 2, Page 3 links), I would put this part, right?

PHP:
if ($_GET['page'] > 0 && $_GET['page'] < 6)
    include("$_GET[page].html");
And then I would have a second file to put the rest of the script in? And according to the way the script it written, what would be the name of this second file?
 

MMJ

Guest
Joined
Oct 15, 2006
Messages
3,625
Pretty much. Play with it and you will understand how it works. :)
 
Joined
Nov 22, 2003
Messages
6,052
whoops, yeah my code shouldn't have the $i + 1, just the $i, but whatev
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top