Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: read more link

  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post read more link

    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?

  • #2
    mtd
    mtd is offline
    Regular Coder
    Join Date
    Jun 2003
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is obviously a very simplified version, but:
    PHP Code:
    <?

    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!
    Last edited by mtd; 06-11-2005 at 12:10 AM.

  • #3
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks. i'll try that one out.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •