tags:

views:

74

answers:

2

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 down to is: how do I get a WordPress page/post into an external PHP file?

Full site: http://capitalchurch.com/beta/ Mobile: http://capitalchurch.com/mobile/

+2  A: 

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).

Jeff
I suppose I should have been more clear.I've found a fantastic iPhone-esque web framework called jqTouch, based on jQuery. Basically the entire website exists in a flat file, and the Javascript handles the iPhone-style transitions between pages. I just need the PHP to grab a page content out of WordPress and display it in the post. (It's an events page that I want displayed in the mobile version).
S Pangborn
I can't think of how you would access the WP loop in an external file, so if it's an external file I suspect your only choice is to do a SQL query directly to the WP database. However, I updated my answer with a possible method of using a page template to get you access to the loop.
Jeff
Oh, excellent! I didn't even think of this. Thanks!
S Pangborn
+2  A: 

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.

Strider
It might be frowned upon but it works and it's easy and that's what matters. Here's a post that describes this method in more detail - http://blog.pakakuy.com/node/249
Ghostrider