0 votes
in Website Design by (1.9k points)

I want to create a page on other part on my website (outside wordpress directory) where I can show list of posts from a specific category.
I am looking for exact solution provided by @toscho here: How to create tabled index of posts in a certain category

For example, if my wordpress site is example.com/blog/, I want to create a standalone solution (php script) which will show list of posts from the wordpress site based on the category. Something like: example.com/category.php.

Is this possible with RSS or any other solution?

Can anyone help me to solve this problem?

1 Answer

0 votes
by (2.4k points)

If files are on the same server & you want to load them from the wordpress environment(using wordpress functions), you can include wp-load.php which will load all wordpress files & then use WP_Queryget_posts etc. This is dirty but gets the job done

If you have the database accessible, you can write custom queries to the database, this will be most efficient but you won't have any wordpress filters applied

It's possible via feed as well, see this example

$doc = new DOMDocument();
$doc->load('< feed url here >');
$arrFeeds = array();
foreach ($doc->getElementsByTagName('item') as $node) {
    $itemRSS = array ( 
      'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
      'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
      'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
      'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
    array_push($arrFeeds, $itemRSS);

If you feel any problem then freely ask!