简体   繁体   English

如何将网站嵌入 wordpress 页面?

[英]How can I embed a website into a wordpress page?

I have one wordpress website & one mvc framework based website.我有一个 wordpress 网站和一个基于 mvc 框架的网站。 let suppose url's as假设 url 为

  1. http://example.wordpress http://example.wordpress
  2. http://example.mvc http://example.mvc

Actually I want to show content of http://example.mvc on http://example.wordpress/page .其实我想在http://example.wordpress/page上显示http://example.mvc的内容。

Note: The http://example.mvc has multiple urls.注意: http://example.mvc有多个 url。 It can be achieve by creating multiple pages but I don't want this.它可以通过创建多个页面来实现,但我不想要这个。 Please help me to solve this.请帮我解决这个问题。

Thanks谢谢

First of all you need to edit the page.php of your theme.首先,您需要编辑您的主题的页面。php。 If you do not want to do it for all pages, you can create a page template.如果您不想对所有页面都这样做,您可以创建一个页面模板。 Just copy the page.php and call it page-yourname.php (choose name you like to).只需复制 page.php 并将其命名为 page-yourname.php(选择您喜欢的名称)。 At top of this page you add "Template Name: Yourname".在此页面顶部添加“模板名称:您的姓名”。 This way wordpress will use it as a page template.这样 wordpress 将使用它作为页面模板。 You can now choose it from the dropdown on the right side on your page edit in backend under the "page attributes".您现在可以从“页面属性”下后端页面编辑右侧的下拉列表中选择它。

There are multiple ways to display content from another website.有多种方法可以显示来自另一个网站的内容。

  1. Using iframes:使用 iframe:

<iframe src="http://example.mvc" width="100%" height="300">
</iframe>
  1. Using embed:使用嵌入:

<embed src="http://example.mvc" width="100%" height="300" />
  1. Using Rest API (and ie Vue JS)使用 Rest API (即 Vue JS)

If you just want to get the posts from another wordpress site you can use the Rest API to get this posts and display it on any other webpage.如果您只想从另一个 wordpress 站点获取帖子,您可以使用 Rest API 获取此帖子并将其显示在任何其他网页上。 For example you can use Vue JS to display it inside of your page template:例如,您可以使用 Vue JS 在页面模板中显示它:

<!-- development version, includes helpful console warnings -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

<div id="posts">
    <div v-bind:key="post.title.rendered" v-for="post in posts">
        <a v-bind:href="post.link"><img v-bind:src="post._embedded['wp:featuredmedia']['0'].media_details.sizes.medium_large.source_url"></a>
        <a v-bind:href="post.link"><h4 v-html="post.name"></h4></a>
        <p v-html="post.title.rendered"></p>
    </div>
</div>

<script>
new Vue({
el: '#posts',
data: {
    posts: [],
},
mounted() {
    fetch("https://yourWordpressURLhere.com/wp-json/wp/v2/posts?per_page=20&_embed=wp:term,wp:featuredmedia")
        .then(response => response.json())
        .then((data => {
            this.posts= data;
        }))
}
});
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM