PHP code example of baraja-core / wordpress-post-feed
1. Go to this page and download the library: Download baraja-core/wordpress-post-feed library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
baraja-core / wordpress-post-feed example snippets
$feed = new \Baraja\WordPressPostFeed\Feed;
$feed->updateCache('https://blog.example.com/feed/');
$feed = new \Baraja\WordPressPostFeed\Feed;
$feed->clearCache();
// cron.php - Run every hour
$feed = new \Baraja\WordPressPostFeed\Feed;
$feedUrls = [
'https://blog.example.com/feed/',
'https://another-blog.com/feed/',
];
foreach ($feedUrls as $url) {
$feed->updateCache($url);
}
foreach ($posts as $post) {
// Original external URL (from WordPress)
$externalUrl = $post->getMainImageUrl();
// Local absolute URL (your domain)
$absoluteUrl = $post->getAbsoluteInternalUrl();
// Local relative URL (for use in templates)
$relativeUrl = $post->getRelativeInternalUrl();
}
use Nette\Caching\Storages\MemcachedStorage;
$memcached = new Memcached;
$memcached->addServer('localhost', 11211);
$storage = new MemcachedStorage($memcached);
$feed = new \Baraja\WordPressPostFeed\Feed(storage: $storage);
$imageStorage = new \Baraja\WordPressPostFeed\ImageStorage(
storagePath: '/var/www/html/assets/blog-images',
relativeStoragePath: 'assets/blog-images',
);
$feed = new \Baraja\WordPressPostFeed\Feed(imageStorage: $imageStorage);
$feed = new \Baraja\WordPressPostFeed\Feed(
expirationTime: '30 minutes',
);
final class BlogPresenter extends Nette\Application\UI\Presenter
{
public function __construct(
private \Baraja\WordPressPostFeed\Feed $feed,
) {
}
public function renderDefault(): void
{
$this->template->posts = $this->feed->load(
url: 'https://blog.example.com/feed/',
limit: 5,
);
}
}