I have been working on one of my websites. On my websites for SEO purposes I create hyperlinks on the bottom of all my pages interlinking one another... This is fine for a small site, but my site has over 100 pages and it not only looks spammy now but doesnt help with SEO in my opinion. What I am trying to do is get all the files in the directory and create only 4 hyperlinks at the bottom of the page, starting with the page we are on. The problem is starting the list with the page we are currently on... as of now my program just prints out the same 10 hyperlinks starting with the beggining of the directory. Any Ideas how I can accomplish this.. the page should displace the links like this Example of page2.php Links: page2.php page3.php page4.php page5.php Example of page3.php Links: page3.php page4.php page5.php page6.php etc etc..... My Code echo "Links: "; if ($handle = opendir('.')) { while (false !== ($file = readdir($handle)) && $i != 4) { if ( $file != "." && $file != ".." ) { //generate clean title= attribute based on filename stripping slashes and extention $file2 = str_replace("-", " ", $file); $file2 = str_replace(".php", "", $file2); $file3 = str_replace("san jose", "", $file2); echo '<li><a href="'.$file.'" title="'.$file2.'">'.$file3.'</a></li> '; echo "\n"; $i++; } } closedir($handle); } PHP:
Well, the basic process i would suggest would be following: 1) Instead of echoing the file names and links, build an associative array. 2) After that, sort the array based on content of "$file" variable 3) Find out the current page/script file name using either $_SERVER['SCRIPT_NAME'] or $_SERVER['REQUEST_URI'] 4) Find the index of the current file name inside the array you built and print it out as link. Do the same with elements in array at [current_index+1], [current_index+2] and [current_index+3] and there you have your 4 links.