ℹ️
Welcome to the archive of the old FlatPress support forum. Browse more than a decade of FlatPress wisdom! Login is disabled.

The current FlatPress support forum is available here: forum.flatpress.org
[Solved] how to create a post both in flatpress and html?
  • Hello,
        when I insert a post I'd like to generate also an HTML version, always with the same name and saven in the same place so that I can import it in another page with <iframe>.

    Does anyone knows how to do it?

    If yes, please, be very detailed I'm totally new with flatpress!!!

    ciao
       matteo

  • The posts themselves exist as text files so you could just use them instead of going to the trouble of creating an html version, but how would your iframe know which file name to look up? What are you trying to achieve, exactly?
  • hello Stanley,
       I always need to get the last post published. Maybe I also need to select the last by category.

    matteo
  • I would just use SimplePie and set it to get the most recent post from your FlatPress blog's RSS feed.

    Here's an example which displays the last post from the official FlatPress blog.

    SimplePie-Example.zip (71kb)

    View Demo

    Just change the feed url on line 13 to show your own blog's feed address. It should be pretty easy for you to work this into your own web page, or build one around this example.

    If you look at line 74 it shows you how to set it to display however many posts you want, but this example is set to just display the last one.

  • Hello Stanley.
    Thank you!
    I saw other similar request where you answered the same "use simple pie" and I try.
    I got something using simplepie_1.3.1.mini.php and simplepie_1.3.1.compiled.php.
    I also found a script (maybe yours... sos) In any case the script is not working fine since it does not update, When I enter a new post I still get the old one.
    I have managed to have it fully working with last post displayed but adding some lines at the beginning to clean the cache but I'm not sure that this approach is correct.

    here is the script:
    <code>
    <?php
     
    require 'simplepie_1.3.1.compiled.php';

    // clean cache
        define('PATH', 'cache/');
        
        function destroy($dir) {
            $mydir = opendir($dir);
            while(false !== ($file = readdir($mydir))) {
                if($file != "." && $file != "..") {
                    chmod($dir.$file, 0777);
                    if(is_dir($dir.$file)) {
                        chdir('.');
                        destroy($dir.$file.'/');
                        rmdir($dir.$file) or DIE("couldn't delete $dir$file<br />");
                    }
                    else
                        unlink($dir.$file) or DIE("couldn't delete $dir$file<br />");
                }
            }
            closedir($mydir);
        }
        destroy(PATH);
    // end clean cache
     
    //$url = 'http://www.rifugiocolombe.it/flatpress/rss.php';
    $url = 'http://www.rifugiocolombe.it/flatpress/?x=feed:rss2&';
     
    $feed = new SimplePie();
    $feed->set_feed_url($url);
    $feed->init();
     
    // default starting item
    $start = 0;
     
    // default number of items to display. 0 = all
    $length = 1;

    // default partial output
    $pout = 70;
     
    // if single item, set start to item number and length to 1
    if(isset($_GET['item']))
    {
            $start = $_GET['item'];
            $length = 1;
    }
     
    // set item link to script uri
    $link = $_SERVER['REQUEST_URI'];
     
    // loop through items
    foreach($feed->get_items($start,$length) as $key=>$item)
    {
     
            // set query string to item number
            $queryString = '?item=' . $key;
     
            // if we're displaying a single item, set item link to itself and set query string to nothing
            if(isset($_GET['item']))
            {
                    $link = $item->get_link();
                    $queryString = '';       
            }
     
            // display item title and date   
    //        echo '<a href="' . $link . $queryString . '">' . $item->get_title() . '</a>';
            echo $item->get_title();
            echo ' <br><small>' . $item->get_date() . '</small><br>';
        echo ' <small>' . substr($item->get_content(), 0, $pout) . '...</small><br>';
     
            // if single item, display content
            if(isset($_GET['item']))
            {
                    echo ' <small>'.$item->get_content().'</small><br>';
            }
            echo '<br>';
    }
     
    ?>
    </code>

    I'll try also the code you proposed.

    By the way, looking quickly into simplepie_1.3.1.......php I have notices a couple of variables that seems to be aimed at management of cache duration, one is set to 1 minute and the other to 7 days... any hint?

    ciao
        matteo

  • No, sorry - I've never been that deep into it. I just use v1.2.1 which seems to do what I need - that's the version which is in the zip file I linked to.

    I changed the feed url on my example page to your own feed. Maybe you could check it now then do a test post to see if it changes when you refresh the page. I just tried this with another FP blog I have and it worked ok for me.

  • It looks fine for me. Try clearing your cache.
    It's not working with my feed (http://mahtava.allalla.com/blogs/main/?x=feed:rss2&).
Start a New Discussion

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion