I'd like to allow my site map to be automatically updated when links are added to subpages. Is there a way to only include the links from other files, and none of the other stuff?
Announcement
Collapse
No announcement yet.
include links only
Collapse
X
-
Tags: None
-
There are two ways to do this I suppose.
One would be to include your links in a database, and so when you add new links, you add them to your database, and they will show up in your site map, as well as your sub-pages.
The other way would be to have your site map code to parse all the other pages for <a href=... tags and grab the links, and display them on the site map.
Which is easier? Probably the database solution, however, you'll have to rewrite some of your code in your other pages. However, if you've got a lot of links and a lot of different pages, then it might be easier to write the parsing routine instead of adding all the links to the database.
Hope that helps,
Sadiq.
-
I'm trying to figure out the 2nd option you mentioned: parsing the files for the links. I can't quite find the right function on php.net though, can you point me in the right direction?
Comment
-
Here's what I have, and it works, but I still have issues.
PHP Code:<?php
ob_start();
include("txt/belief_main.txt");
$belieflinks = ob_get_contents();
$belieflinks = str_replace('\"', "", $belieflinks);
$belieflinks = str_replace('reglink', "sitemaplink", $belieflinks);
ob_end_clean();
echo "<a href=believe.html?page=main class=red>
Some of the Things That I Believe</a><br> ";
preg_match_all("|<a[^>]+>(.*)</[^>]+>|U", $belieflinks,
$out, PREG_PATTERN_ORDER);
echo $out[0][0] . "<br> " . $out[0][1] . "<br> ";
echo $out[0][2] . "<br> " . $out[0][3] . "<br> ";
echo $out[0][4] . "<br> " . $out[0][5] . "<br> ";
echo $out[0][6] . "<br> " . $out[0][7] . "<br> ";
echo $out[0][8] . "<br> " . $out[0][9] . "<br><br>";
?>
Issue #2 - When a file has less than 10 links, there is an unneccessary amount of blank space below the links (due to the <br> tags), is there some way that I can say if_exists ($out[0][8]){echo $out[0][8]}?
Issue #3 - When a file has more than 10 links, is there a way to (in addition to the previous issue) set up a variable that increments the # of the link that the code seeks to include?Last edited by BroChris; Feb 19, 2004, 08:29 AM.
Comment
-
Disregard issues 2 and 3. A simple while function solved it:
PHP Code:$i=0;
while (isset($out[0][$i]))
{
echo $out[0][$i] . "<br> ";
$i++;
}
Last edited by BroChris; Feb 19, 2004, 03:44 PM.
Comment
Comment