[thelist] PHP to insert press Releases into a detail page

jono at charlestonwebsolutions.com jono at charlestonwebsolutions.com
Fri Sep 23 15:15:40 CDT 2005


> JYoung at sawgrassink.com scribeva in 2005-09-23 13:54:
>> I have about 40 press releases that are part of a site redesign.
>
>> Is it possible to copy the current articles into a text file, and then
>> use PHP includes to drop in the appropriate article depending on the
>> link that is click by the user?
>>
>> I am looking for the easiest, most efficiently simple solution of
>> course.
>
> About the easiest way to go is to put all the articles in one array and
> use that for both index and detail pages. Put that array in a file of
> its own, say pr_articles.php, and in it:
> <?php
> $articles = array();
> $articles[] = array(
>     'date' => '2005-09-20',
>     'title' => 'First title',
>     'body' => 'First pr's text');
> $articles[] = array(
>     'date' => '2005-09-21',
>     'title' => 'Secondtitle',
>     'body' => 'Second pr's text');
>
> ?>
>
> Then on
>> Index page:
>
> <?php
> require "pr_articles.php";
> ?>
> ...
> <?php
> for ($i = 0; $i < count($articles); $i++){
>     echo "<a href='pr_detail.php?article=" . $i . "'>"
>        . $articles[$i]['title'] . "</a><br>";
> }
> ?>
>
>
> And on
>> Detail page:
>
> which is called pr_detail.php
>
>> <div id="press-releases">
>
> <?php
> $id = $_GET['article'];
> echo "<h1>" . $articles[$id]['title'] . "</h1>"
>     . "<h2>date: " . $articles[$id]['date'] . "</h2>"
>     . $articles[$id]['body'];
> ?>
>
>> </div>
>
> Not that this example assumes you'll include body's markup in the array,
> like "<p>first paragraph</p><p>second</p>".
>

Seems pretty easy...or atleast I can follow what is going on enough to be
able to figure it out.  One thing I am not sure about:

Does the following create a list of links that users click on:?
> <?php
> require "pr_articles.php";
> ?>
> ...
> <?php
> for ($i = 0; $i < count($articles); $i++){
>     echo "<a href='pr_detail.php?article=" . $i . "'>"
>        . $articles[$i]['title'] . "</a><br>";
> }
> ?>

I believe it does - I see the echo "<a href=...> - but I just wanted to
make sure that was the case.

Thank you so much for the (apparently) simple solution!


More information about the thelist mailing list