WordPress.org

Forums

Last 5 Posts query in plain HTML (5 posts)

  1. frieder
    Member
    Posted 9 years ago #

    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

  2. Arne Brachhold
    Member
    Posted 9 years ago #

    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="http://www.yourblog.com/feed/";
    $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.

  3. davidchait
    Member
    Posted 9 years ago #

    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

  4. frieder
    Member
    Posted 9 years ago #

    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 ...?

  5. Arne Brachhold
    Member
    Posted 9 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic