View Full Version : read more link

06-10-2005, 07:40 PM
some sites that has articles, the article's first few lines are shown and beside it is a link that says "read more".

how can i do that?

06-11-2005, 12:59 AM
This is obviously a very simplified version, but:

function articleSample($location,$title) { // Define function w/ "$location" as the location of the article file and "$title" as its title

$pageContents = file_get_contents($location); // Read the contents of the file into an array
$charMax = 100; // Set the maximum # of characters to display from the article

echo "<b>".$title."</b><br>"; // Prints the Article Title before the article snippet

for($i=0; $i < $charMax; $i++) { // while $i is less that your character limit...
echo $pageContents[$i]; // ...prints character "$i" to the page

echo "... <b>[<a href=\"".$location."\">READ MORE</a>]</b>"; // Prints the "Read More" at end, with a link to the article as defined above

articleSample("article1.htm","This is the title"); // Call the articleSample() function, defining the location of your article and the article title
// note that thess can be a variables if your article locations/titles/etc. are stored as a variable or in an array - this allows for more flexibility

?> This should work as a basic script, if you modify it a bit I think you'll be able to incorporate it well into your site. (NOTE: this assumes that the only content on you "article1.htm" is the article itself, meant to be included into a template or something. If the article page has html headers or any of that, this will require more modification to skip those parts)

Hope this helps!

06-11-2005, 03:18 AM
thanks. i'll try that one out.