ℹ️
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
Getting FlatPress posts via PHP
  • I am currently coding a new website for my company-ish-organization-ish thing, and I use FlatPress for my blog. I have it installed at /blogs/main (I have a personal one installed, too). I would like to keep that up, but also grab the latest FlatPress posts via PHP at /newsite/index.php (soon will just be /index.php). I would use the actual FP installation, but want the latest posts to be displayed on /newsite/index.php just like they are for the actual FP installation, with a link and everything. I could do this via RSS (it has a feed), but I think it would be nicer to display them this way.
  • You mean display posts from both FP blogs on one of them? There may be a better solution to it but I would be looking at using the RSS feed from the 2nd blog if I was going to attempt something like that.

    There's a SimplePie plugin on the Wiki but this only creates a widget which you would normally place on your sidebar but there's nothing to stop you using that to display the feeds from both blogs using that plugin instead of the standard lastentries plugin.

    That being said there's nothing to stop you rewriting your index.tpl to show those two feeds using SimplePie directly (without the plugin). You can use php in template pages by enclosing the code in {php}{/php} tags.

    Bear in mind that your blog's search function will only search the posts on that particular blog.

  • No, I only want to grab post from one of them and put them on an entirely different PHP file.
  • In that case I would personally use the RSS feed and SimplePie - in fact I have done that before here. I've always found SimplePie to be easy to work with to get it to display things just how you want. The example linked to here just shows the post titles, but you can show more or less depending on what you want.
  • I would like it to grab the title (and have that be a link) and post content just like the FP blog does, though; not just have a simple little widget. If I only wanted that, I would have thrown the feed URL into Feedroll already.
  • Well, SimplePie can display as much or as little of the post as you want. You can see an example here which also includes a few lines of the post itself.

    This is hard coded into the page - both of these examples are external (non-FP) php pages. You can get SimplePie to display the posts in a whatever style you want though if you've used the readmore or autoreadmore plugins to chop an entry then the chopped entry is all you will be able to display. SimplePie itself allows you to chop entries to a certain number of characters, or to the end of a sentence.

    I don't know Feedroll, maybe it does the same thing or maybe SimplePie is more suited to what you want to do. Take a look at the code here to see if it's for you...

    http://www.simplepie.org/wiki/setup/sample_page

  • Hi, if you want only the titles you could create a plugin like the last entry plugin to create a cache with titles.
    Then you load it from your other site and your request is done.

    If you want also the conten, it's more difficult. It would be easier make the other site inside Flatpress.
  • Isn't there just a simple script that can grab x latest posts and display the content, title, and link it to the post? I was looking around in FP and wasn't getting anywhere. Basically, I only want the homepage of FP where it grabs the posts, nothing else. The other site isn't FP; it's just PHP I wrote.
  • No there isn't.
    However you can write your own plugin that caches these x entries.
    Then you open the cache with your scripts and show it.
    However you have to remove special plugins, such as analytics etc.
  • I'm trying to use the tutorial at http://www.onextrapixel.com/2009/12/24/how-to-build-a-php-based-rss-feed-parser/ to parse posts, but it gives me all the following errors when I use it with the feed FP gives me:
    Warning: simplexml_load_file() [function.simplexml-load-file]: http://mahtava.allalla.com/blogs/main/?x=feed:rss2&1:1: parser error : Document is empty in /home/u599980382/public_html/newsite/parserfunctions.php on line 14
    Warning: simplexml_load_file() [function.simplexml-load-file]: in /home/u599980382/public_html/newsite/parserfunctions.php on line 14
    Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /home/u599980382/public_html/newsite/parserfunctions.php on line 14
    Warning: simplexml_load_file() [function.simplexml-load-file]: http://mahtava.allalla.com/blogs/main/?x=feed:rss2&1:1: parser error : Start tag expected, '<' not found in /home/u599980382/public_html/newsite/parserfunctions.php on line 14
    Warning: simplexml_load_file() [function.simplexml-load-file]: in /home/u599980382/public_html/newsite/parserfunctions.php on line 14
    Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /home/u599980382/public_html/newsite/parserfunctions.php on line 14
    Warning: Invalid argument supplied for foreach() in /home/u599980382/public_html/newsite/parserfunctions.php on line 17
  • I'm trying it, but it isn't working. It doesn't show any errors, so I'm assuming it has to be an issue with the feed. I haven't touched any of the FP code, so I couldn't have done much to it.
  • Your feed seems to work when I plugged it into the example on my site?

    http://www.us2uk.eu/simplepie-example.php

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