开发者

Include WordPress Content Outside of WordPress

I'm looking to build a mobile version of a WordPress site and have most of it built in static files, but am trying to get access to the WordPress content from inside an external PHP file that the mobile site will run from. How can I get access to the loop or database without manually writing SQL queries?

Edit: Just to clarify, I'm using jqTouch for the Mobile version.

jqTouch uses a single php file to display several "pages" of content, which are then navigated via the Javascript hiding/showing the content.

What it really boils do开发者_如何学Gown to is: how do I get a WordPress page/post into an external PHP file?


There's a "cheater" method and an officially sanctioned method to do what you want.

The "cheater" method is to call wp-load.php from you separate PHP file. This will load the WP database stuff and give you access to WP functions. This method is easier but somewhat frowned upon because it can cause problems in certain setups.

The official way to do it is to go from within WordPress itself. Specifically throw in some code (in plugin or theme) that hooks the "template_redirect" action and you should be able to redirect any URL you like to whatever PHP file you want -- while still having access to WP because you're running from within WP.


If your goal is to simply have a second version of your site that uses a mobile-friendly theme, how about a plugin that will do this? For example: WordPress Mobile Pack

BTW, I'm not clear on what you are looking to accomplish, because first you say you want the mobile site to be mostly static, but then you say that the mobile site will use PHP, which isn't static. Can you clarify how the mobile site should work?

Edit:

Now that I get what you're doing, I have a thought as to how you could do it. Create a custom page template that includes the WP loop and the jqTouch code. Then create a WP page that uses this custom template (page content can be blank if all the content is provided by the template).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜