Forum Moderators: coopster
this is the basic layout of a particular page:
articles.php
-----------------------------
header
-----------------------------
link to article1
link to article2
link to article3
link to article4
etc
-----------------------------
footer
-----------------------------
what i want to achieve is - all of the content for links 1-4 are within articles.php. when a link is clicked, the links would disappear and the article content displayed.
is this possible?
thank you in advance.
:)
I think in this instance you could use a variable in the url to display the appropriate article once clicked.
your links could look something like this
<a href="articles.php?article=1">article1</a>
then do a test to see is the variable is set
if (!isset($_GET['article']) ¦¦ $_GET['article'] == "") {
// echo all links
} else {
// echo individual content
}
is all the content smashed into the one file or is the actual content in seperate files?
If the content is stored in seperate files you could do
} else {
$articlepage = "article" . $_GET['article'] . ".html";
include $articlepage;
} this would assume that the articles are located in the same directory and are named article1.html, article2.html etc.
or if all the content is smashed in there you could use a switch
} else {
switch ($_GET['article']) {
case 1:
// article1 content
break;
case 2:
// article2 content
break;
case 3:
// article3 content
break;
}
} one case for each article, though that may make that file fairly huge as time goes on
i'm getting a parse error on line 7:
<a href="articles.php?article=1">article1</a>
<a href="articles.php?article=2">article2</a>
<a href="articles.php?article=3">article3</a>
<?php
if (!isset($_GET['article']) ¦¦ $_GET['article'] == "") {
// echo all links
} else { switch ($_GET['article']) {
case 1:
article1 content
break;
case 2:
article2 content
break;
case 3:
article3 content
break; } }
?>
checkout the nice include() [php.net] function. you can simply load in each article, so you can divide the one-big-file into manies.
--hakre