I'm new to PhP.
I am interested in setting up an article directory so that specific article(s) can then be called into a given template.
So say I have directory "A" something like http://test.me.com/articles/
I would then have files named something like atcl0001.htm, atcl0002.htm, atcl0003.htm, etc in the above directory.
Then I have a link on another page page that calls a specific article within that article directory.
The link might look like http://test.me.com/articles.php?getid=105 and would load the target article into this example template page.
The result would be I only need 1 template page to output the given article directory.
What I would like to know, is there an easy way to impliment something like this?
I'm sure there are several ways and easy to use PhP scripts. I'm just so PhP ignorant, I am not sure where to begin.
BTW, little snipbits of code doesn't help me at all at this point. I could really use an entire script to understand what is going on with something like this.
Thanks for any help
PhP Article Output
Moderator: General Moderators
- no_memories
- Forum Contributor
- Posts: 145
- Joined: Sun Feb 01, 2004 7:12 pm
- Location: New York City
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
Just read the variable in the url - i.e. $_GET[getid] and then this will relate to the given file, for example your files maybe named:
artical_1.php
artical_2.php
etc
Using the varible value you can construct a file name and path i.e.:
$filename = "path/to/articals/artical_".$_GET[getid].".php";
Then do some checks to see if this file exists and include the page if it does
if(file_exists($filename)){ #makes sure the file exists
include($filename);
}else{
echo "Invalid artical";
}
artical_1.php
artical_2.php
etc
Using the varible value you can construct a file name and path i.e.:
$filename = "path/to/articals/artical_".$_GET[getid].".php";
Then do some checks to see if this file exists and include the page if it does
if(file_exists($filename)){ #makes sure the file exists
include($filename);
}else{
echo "Invalid artical";
}
- no_memories
- Forum Contributor
- Posts: 145
- Joined: Sun Feb 01, 2004 7:12 pm
- Location: New York City
Thanks for the info.
I do follow what you are saying, lol, but here is the 99 million $$$ question.
I'm not sure how to write the actual link that would reach out to the article directory.
example link: <p>blah blah blah blah blah blah <a href="$filename = "path/to/articals/artical_".$_GET[getid].".php"">article01.php</a> blah blah blah blah blah blah</p>
I'm guessing the php value for the link would need to have some identifier for the output page?
example output on template page: <div id="artclop"><?php echo $_POST["articleoutput"]; ?></div>
I'm guessing this would be the proper way of accomplishing something like this?
I already have something similar now with certain content. An example would be: <div><?php require("content/index-pi.php"); ?></div> But this doesn't require a link to post the results on another template page. It simply grabs the given page and posts it within the same document.
BTW, here is the site I want to incorporate this with - a tableless xhtml site. http://www.thexvector.us/
I do follow what you are saying, lol, but here is the 99 million $$$ question.
I'm not sure how to write the actual link that would reach out to the article directory.
example link: <p>blah blah blah blah blah blah <a href="$filename = "path/to/articals/artical_".$_GET[getid].".php"">article01.php</a> blah blah blah blah blah blah</p>
I'm guessing the php value for the link would need to have some identifier for the output page?
example output on template page: <div id="artclop"><?php echo $_POST["articleoutput"]; ?></div>
I'm guessing this would be the proper way of accomplishing something like this?
I already have something similar now with certain content. An example would be: <div><?php require("content/index-pi.php"); ?></div> But this doesn't require a link to post the results on another template page. It simply grabs the given page and posts it within the same document.
BTW, here is the site I want to incorporate this with - a tableless xhtml site. http://www.thexvector.us/
Some pseudo-code for the container page:
To navigate to another article:
<a href="articles.php?article=$someArticleName">click for an article</a>
That's really all there is to it. Of course, then you need to have a separate .php (or whatever) file for each article. Depending on the size of your site, an even better way might be to hold them all in an array(?) or database.
Code: Select all
<?
$article = $_GET['article'];
?>
<head />
<body>
<?
include_once $article . ".php"
?>
</body><a href="articles.php?article=$someArticleName">click for an article</a>
That's really all there is to it. Of course, then you need to have a separate .php (or whatever) file for each article. Depending on the size of your site, an even better way might be to hold them all in an array(?) or database.
- no_memories
- Forum Contributor
- Posts: 145
- Joined: Sun Feb 01, 2004 7:12 pm
- Location: New York City
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England