Recent posts on static html pages problem?

by skyvia
1 replies
  • WEB DESIGN
  • |
I have a section on my site in every page that has 'recent posts' and have just realised that i may have to update my static html pages to change the recent posts as with blogger or word press it changes automatically.
Is there anyway i can add code so that it updates automatically?
#html #pages #posts #problem #recent #static
  • Profile picture of the author Mkj
    You can update such pages with code similar to this:

    <?php

    $data = "This message will be printed into printed.txt file";

    $file= fopen("printed.txt", "w");
    fwrite($file, $data);
    fclose($file);

    $file2= fopen("printed2.txt", "w");
    fwrite($file2, $data);
    fclose($file2);

    echo "Printed.txt updated!";
    echo "<br>";
    echo "Printed2.txt updated!";

    ?>

    The print.txt file will need to have write permissions 0777. You simply include the altered file into whatever page you need using php include or similar.

    The $data can be put inside a while loop even and it will work from there - similar to this:

    <?php

    // Database connection
    require('../config.php');

    $result = mysql_query("select query here")
    or die(mysql_error());

    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {

    $data .= "" . $row['row name here'] . "\r\n";

    } ;

    $file= fopen("printed.txt", "w");
    fwrite($file, $data);
    fclose($file);

    $file2= fopen("printed2.txt", "w");
    fwrite($file2, $data);
    fclose($file2);

    echo "Printed.txt updated!";
    echo "<br>";
    echo "Printed2.txt updated!";

    ?>
    {{ DiscussionBoard.errors[3841048].message }}

Trending Topics