M
M
MrFlatman2020-02-26 10:43:06
WordPress
MrFlatman, 2020-02-26 10:43:06

Auto-import news to another site?

There is a situation, there is a main site, and there are several child sites, about 5 pieces (yes, for almost every department), there is a need that when adding news on the main site, it is also added to all child sites, all WordPress sites, Are there any plugins that can help with this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2020-02-26
@Elgorm

Check out this article https://hostenko.com/wpcafe/tutorials/rss-auto-pos...

M
Markusan, 2020-02-27
@Markusan

I don't work with worpdress on a permanent basis. Perhaps there is a better solution.
You can get what you need through JSON that gives the site to wordpress.
What should be done?
1. Send a request to the site to receive data about the latest posts.
2. "Draw" what we need from the incoming answer (title, link, heading, thumbnail).
3. Display on the page.

Code

Запрос на 3 последних поста. «Вытягиваем» из ответа заголовки и вставляем на страницу
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div class="get-title"></div>
  <div class="get-title"></div>
  <div class="get-title"></div>
</body>


<script>
var titleFirstPost = document.querySelectorAll('.get-title')[0];
var titleSecondPost = document.querySelectorAll('.get-title')[1];
var titleThirdPost = document.querySelectorAll('.get-title')[2];

var ourRequest = new XMLHttpRequest();
ourRequest.open('GET', 'http://wundermag.thememeister.com/wp-json/wp/v2/posts?per_page=3&_embed');
// wundermag.thememeister.com - ссылка на ваш сайт
ourRequest.onload = function () {
    if (ourRequest.status >= 200 && ourRequest.status < 400) {
        var data = JSON.parse(ourRequest.responseText);
        console.log(data);
        createHTML(data);
       
    } else {
        console.log("We connected to the server, but it returned an error.");
    }
};

ourRequest.onerror = function () {
    console.log("Connection error");
};

ourRequest.send();

function createHTML(HTMLdata) {
titleFirstPost.innerHTML = HTMLdata[0].title.rendered;
titleSecondPost.innerHTML = HTMLdata[1].title.rendered;
titleThirdPost.innerHTML = HTMLdata[2].title.rendered;
}
</script>
</html>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question