Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

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_Query, get_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

<?php
$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);
}
var_dump($arrFeeds);
?>

or use curl to read feeds, there are tutorials easily available online

share|improve this answer
    
Mridul: Sorry for the delayed response. Actually I was moved to other project. Now I got this one and need to find the solution asap. Could you please let me know if the above solution works on an environment like: Wordpress Installed Location: www.mysite.com/wordpress/ Categories list page: www.mysite.com/categories.php Also could you please guide me on the cutom SQL queries for this. I think this would be the perfect way to fetch the data. I need to fetch from a specific category with it's image associated with. Please help. –  SachinKRaj Nov 22 '12 at 9:41
    
Maybe SELECT * FROM wp_posts INNER JOIN wp_term_relationships ON wp_term_relationships.object_id = wp_posts.ID WHERE wp_term_relationships.term_taxonomy_id = "2". Use the correct term taxonomy id. For the featured image, the id is stored in wp_postmeta table with the key thumbnail_id. I think you can associate the image together with the above query using some complex joins. –  Mridul Aggarwal Nov 22 '12 at 11:33
    
It seems the site is the same. Why don't create the page in wordpress and use a rewrite rule in .htaccess to display the page as it is out of wordpress folder? –  G. M. Aug 20 '13 at 21:25
    
@G.M. I would also be interested in learning how such a solution would work. example.com/blog/ & example.com probably have different session & for that reason i doubt such a solution will cover all use cases –  Mridul Aggarwal Aug 22 '13 at 15:34
    
Let's assume we have a server with wp installed in /blog subdir and a non-wp environment in the root. In WP we will have a term archive url like, e.g. www.site.com/blog/tax/term/. In the .htaccess file located in the root we manually insert a rewrite rule that statically rewrite www.site.com/term in www.site.com/blog/tax/term/. Maybe I'm wrong, but I think it should works. @MridulAggarwal –  G. M. Aug 22 '13 at 20:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.