0

I have 3 separate sites/installs on the same server and they all use the same database:

  • xxxx.com/en
  • xxxx.com/de
  • xxxx.com/es

I want a <div> from a specific site in xxxx.com/en to appear on the other sites. Let's say I have <div id="table1">xxxx<div> on xxxx.com/en/page1; I want this to show on xxxx.com/de/page1.

I did not think this would be so complicated in WordPress. With plain PHP, it would be just an include, but WordPress is a closed system. So, how can I do this?

2 Answers 2

0

I'd suggest you use a translation plugins. one simple and free such as PolyLang would make that much more easy, and you'd be able to use / create different template pages for each language. here is a link to get started: https://www.wordpress.org/plugins/polylang/

0

Sure, this can be done, but requires some work. Here's the approach I would take:

  1. In the source install, make a page that has its own template, which includes just the <div> you want to pull out (no header, footer, sidebar and so on). In this way you can have the source install assemble the data, just as if it were a regular post. You could even use query_vars if the <div> you want is dynamic. Basically, you make sure the source install delivers the desired html with a call like this:

    http://example.com/en/mydivpage?my_var=something

  2. Now you have to pull this html (which is not a full webpage) into the target install. Probably the easiest way would be to use the jquery load command.

    <script>$("#putithere").load("http://example.com/en/mydivpage?my_var=something");</script> ... <div id="putithere"></div>

  3. Finally, to make this really work, you'll have to solve a security issue. By default browsers won't allow loading html from another domain, unless by iframe. However, you can allow certain trusted domains to violate this rule.

I mentioned the <iframe> option. Under 1. make sure you include <head> and body tags. Then under 2. just include the full webpage. The drawback of this approach is that the target's page css won't work inside the frame.

4
  • Hello, Thanx for this approach...but i want this site to be editable in one wordpress installation...i tried a simple html site, i called it page-test.php, but it does not even show up <!DOCTYPE html> <html> <head></head> <body> testsite </body> </html>
    – taxishop
    Nov 22, 2016 at 14:48
  • Hello, now i made a new page like test1 and i have this output: <!DOCTYPE html> <html> <head> </head> <body>test</body> </html> now i have to get test from that page...how can i do that?
    – taxishop
    Nov 22, 2016 at 16:02
  • Follow the link to jquery load in my answer. You can load parts of a page. But the crossdomain scripting rules still apply.
    – cjbj
    Nov 22, 2016 at 16:20
  • Now i looked into the jquery doc and saw that you can load an element of the page based on an id, so i have now: <!DOCTYPE html> <html> <head> </head> <body><span id="test1">test<span></body> </html> and the jquery would be: $( "#mysnippet" ).load( "en/test1 #test1" ); the problem is now, the snippet test is actually a part of another page... but wordpress does not allow inserting code into the editor-page...
    – taxishop
    Nov 22, 2016 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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