There is no better way . It all depends on how interconnected these sites are and how much you "trust" them.
Using iframe
s
Using iframe
s, as I described in this other answer , is perfectly valid when you want to insert content that is independent of the current page, either for aesthetic reasons, performance or security.
The problem of using iframe
is not so bad that it is bad in itself, but it has several other challenges:
- How to scale frames and keep a layout consistent with the rest of the page?
- What to do with links within the frame?
- Is it necessary to interact with the contents of the frame? In this case it would be necessary to define access header from different sources.
If the content of this Wordpress site you want to include is something that occasionally could cause security issues, like scripting your page, iframe
helps isolate that content.
In addition, if content varies frequently and you can not build a parser , iframe
ends up being the most secure alternative.
Getting content on the server
Using HTML directly
If, on the other hand, you trust that other site, maybe because you are the administrator yourself, you can do as Ricardo suggested in the other answer.
Your server places a request for the other site and retrieves the content of the page you want to insert. Then insert that content into your page.
In addition to security, this technique needs to consider:
- Styles and structure of the other page. They may not work if there are relative paths or they may interfere with the styles and structure of your page.
- Making requests to another server each time you display a page will kill your performance. The ideal would be to keep this information in cache , perhaps in a database, for some time and update from time to time.
Interpreting information
If content always follows the same structure, the most advanced and flexible technique is to make some code to read the content of the other site and extract only relevant information from each product.
With this information on your server, you can treat it yourself to prevent it from being a security risk, such as by encoding in HTML when writing to the page, limiting size, etc. Then you can display them in the format you want.
The second part of Ricardo's response shows this alternative, using an parser of XML. But consider that HTML does not follow the same XML rules, so chances are you'll need to use some specific library to interpret HTML.
Of course, the ideal would be to be able to retrieve data via web services in a friendly format like JSON, but parsing HTML breaks a branch when it is not possible.
If you are the administrator of the Wordpress site, consider that there are some plugins to work with REST. If the site uses a plugin to manage products, it is likely that it has some APIs. Look at the documentation before drawing conclusions.
Finally, to reinforce, this technique does not work well if the information read does not have a defined structure.