[wp-hackers] How to load a sidebar/footer from non-WordPress environment
philip at philipwalton.com
Fri Apr 1 04:57:43 UTC 2011
On 3/31/11 9:26 PM, Matt Martz wrote:
> On Thu, Mar 31, 2011 at 10:49 PM, Philip Walton<philip at philipwalton.com> wrote:
>> Otto, I haven't tried that so I can't confirm, but that sounds like it would
>> almost certainly cause problems. Both Yii and WordPress use htaccess rewrite
>> rules, both use a custom URL structure, and I believe both use
>> cookies/sessions. It just seems like that would get real messy, real fast.
>> And what about a situation where the other pages aren't being built with
>> PHP? I've had similar issues when building applications with a coworker who
>> uses WebObjects (Java).
>> Is this not something anyone here has really had to deal with? It seems to
>> me like it would come up frequently.
>> On 3/31/11 7:57 PM, Otto wrote:
>>> Make a page template and include the Yii base code in that. Then use that
>>> page template on a WP page.
>>> On Thu, Mar 31, 2011 at 7:51 PM, Philip
>>> Walton<philip at philipwalton.com>wrote:
>>>> I'm building a site for a client that is primarily in WordPress but
>>>> contains a donation section built with the PHP framework Yii.
>>>> Visually, when a user is on the donation page(s), I'd like to still show
>>>> the sidebar and footer from the main WordPress blog to maintain
>>>> But, obviously, I can't simply include those php files or call
>>>> from another application.
>>>> I know there are several ways to accomplish what I'm wanting: I could use
>>>> ajax, e.g. $.load(), or create a page template and file($url), but I'm
>>>> looking for a better (and faster) way. I'm wondering if other folks have
>>>> encountered this issue, and what they have done.
>>>> If no good solutions exist, I might just write a plugin that caches theme
>>>> parts periodically or after certain updates are made.
>>>> Any advice?
> WordPress is heavily dependent on the rest of WordPress for page
> generation. There is no simple way to separate out functionality such
> as just rendering the sidebar or just rendering the footer without
> loading the rest of WordPress.
> Attempting to try loading it into java would just be ridiculous. How
> would you plan on executing PHP code outside of using PHP? Trying to
> load it into another PHP application may be possible, but as you point
> out it has the potential to cause issues. In the end, if you want to
> use WordPress then why just not use WordPress, or write the
> functionality you want from WordPress in whatever other application
> you insist upon using.
> I guess technically you could create pages in WordPress and assign a
> page template to it, call the page sidebar and create a page template
> that only displayed the sidebar and assign it to your page. Then you
> could do some sort of HTTP request to that page in WP, and inject the
> HTML into your other page powered by some other app. But that sounds
> like shaving the corners off of the square peg to make it fit into the
> round hole instead of just using the round peg. At that point why not
> just use WP?
If it were up to me, I'd just use WordPress, but quite often it's not
just up to me. When you get hired to incorporate a blog into an existing
site, you just have to play the hand you've been dealt.
Perhaps I'm not doing a very good job of explaining myself. Imagine I've
created a WordPress theme with a footer that displays a list of all the
pages in that site. Then someone else creates another web app for the
same domain that wants to use my footer. Obviously you can't just take a
snapshot of the footer because it will change every single time a new
page is added.
Here is my idea: create a plugin that makes an ajax request to the home
page every time a page is saved to the database. That ajax request would
parse the document for the footer based on a CSS/jQuery selector,
perhaps "#footer", and then save the returned markup as a .html file on
the server. Then, in the other application, the code could simply
include that .html file and be fairly certain it's exactly the same as
what's on the home page.
It seems a little hackish, but I can't really think of a better idea.
More information about the wp-hackers