• I have WordPress running and it works fine. Now I want to display the last five posts on another, plain-Html, webpage. Is there a (php?)script that does the job: querying mysql and displaying the content in html?

    thanx for your answers, frieder

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    i would simply read out your rss feed. Maybe the WordPress database structure will change in the future so query the posts directly is not very safe.

    Just download the Magpie RSS Parser and include the following script on your page:


    <?php

    require_once('magpierss/rss_fetch.inc');

    $url="https://www.yourblog.com/feed/&quot;;
    $num_items = 5;
    $rss = fetch_rss($url);

    $items = array_slice($rss->items, 0, $num_items);

    foreach ( $rss->items as $item ) {
    echo "Title: " . $item['title'];
    echo "Published: " . date("h:i:s A", $published);
    echo "";
    }
    ?>

    More info about Magpie can be found here.

    Well, if the page is plain HTML, no. Not without a server-side include, or javascript. There are a few JS systems that will display feeds.

    If it is a PHP page, you could use my CG-FeedRead plugin, which was built for uses just like this.

    -d

    Thread Starter frieder

    (@frieder)

    hi arnee,

    thanx for your advise – I′ve installed magpie and checked everything so far. it runs but it doesnt work yet.

    I always get the error-message:

    “items, 0, $num_items); foreach ( $rss->items as $item ) { echo “Title: ” . $item[‘title’]; echo “Published: ” . date(“h:i:s A”, $published); echo “”; } ?>”

    do you have an idea what′s wrong with it – the feed-address is ok …?

    Hi,

    you need to place the code in a PHP file. If you hoster supports php, simply rename your .html file to .php and it should work.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Last 5 Posts query in plain HTML’ is closed to new replies.