dora12345678 2014-09-23 15:44
浏览 16
已采纳

php在root php文件中显示来自子文件夹的WordPress帖子

I'm sure that someone can show me how to do this.. My search online seems to be fruitless..

I am needing to display some Wordpress posts from a subfolder installation of WordPress (/news) and I want to call in just some posts to a static page (as this was designed and built before my involvement) in the root directory (for this instance I have made a test.php file.

Does anyone know a way to call a loop from the subfolder installation to display posts on the test.php file?

Any help would be great.

Chris

  • 写回答

1条回答 默认 最新

  • dsgs8208 2014-09-23 15:53
    关注

    You won't be able to access the loop in a wordpress installation in a sub folder because that loop isn't running if you don't hit that index.php page. However there is a very good solution for doing this and I have used it myself in a very similar situation.

    There is a great plugin called json-api for wordpress that you can install on your subfolder /news and it will allow you to easily get the posts from that wordpress install from anywhere else. Your call may look something like:

    /news/api/posts
    

    Which would give you the blog posts from that news install in json format. It's very easy to install and it works like a charm. This plugin is scheduled to move into the Wordpress Core in Wordpress 4.1 https://make.wordpress.org/core/tag/json-api/ which is a very good sign of it's stability.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?