Compare commits
6 Commits
2a594e0974
...
main
Author | SHA1 | Date | |
---|---|---|---|
f515b9d969 | |||
f22e8199e4 | |||
85ff4c0c6c | |||
d6f93f2f42 | |||
5d4d318a50 | |||
b2166a8425 |
@ -7,13 +7,12 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
Module.register('MMM-Wordpress', {
|
Module.register('MMM-Wordpress', {
|
||||||
defaults: {
|
defaults: {
|
||||||
updateInterval: 600000, // 10 minutes
|
updateInterval: 600000, // 10 minutes
|
||||||
url: 'YOUR_WORDPRESS_API_URL', // replace with your WordPress API endpoint
|
url: 'YOUR_WORDPRESS_API_URL', // replace with your WordPress API endpoint
|
||||||
numberOfPosts: 5, // number of posts to display
|
numberOfPosts: 5, // number of posts to display
|
||||||
posts: 'posts', //Endpoint ("posts" for normal posts, can be changed to custom post type)
|
posts: 'posts', //Endpoint ("posts" for normal posts, can be changed to custom post type)
|
||||||
},
|
},
|
||||||
|
|
||||||
start: function() {
|
start: function() {
|
||||||
@ -30,7 +29,7 @@ Module.register('MMM-Wordpress', {
|
|||||||
const numberOfPosts = this.config.numberOfPosts;
|
const numberOfPosts = this.config.numberOfPosts;
|
||||||
|
|
||||||
//hier müssen die posts noch rein!
|
//hier müssen die posts noch rein!
|
||||||
this.sendSocketNotification('GET_POSTS', { url, numberOfPosts });
|
this.sendSocketNotification('GET_POSTS', { url, posts, numberOfPosts });
|
||||||
},
|
},
|
||||||
|
|
||||||
socketNotificationReceived: function(notification, payload) {
|
socketNotificationReceived: function(notification, payload) {
|
||||||
@ -48,7 +47,8 @@ Module.register('MMM-Wordpress', {
|
|||||||
for (let i = 0; i < posts.length; i++) {
|
for (let i = 0; i < posts.length; i++) {
|
||||||
const post = posts[i];
|
const post = posts[i];
|
||||||
const postElement = document.createElement('div');
|
const postElement = document.createElement('div');
|
||||||
postElement.innerHTML = `<h2>${this.stripTags(post.title.rendered)}</h2><p>${this.stripTags(post.excerpt.rendered)}</p>`;
|
//postElement.innerHTML = `<h2>${this.stripTags(post.title.rendered)}</h2><p>${this.stripTags(post.excerpt.rendered)}</p>`;
|
||||||
|
postElement.innerHTML = `<h2>${this.stripTags(post.title.rendered)}</h2><p>${this.stripTags(post.content.rendered)}</p>`;
|
||||||
wrapper.appendChild(postElement);
|
wrapper.appendChild(postElement);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
23
README.md
23
README.md
@ -1,5 +1,28 @@
|
|||||||
|
# Info
|
||||||
|
|
||||||
|
This module for Magic Mirror should display posts from a WordPress site.
|
||||||
|
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
|
|
||||||
|
```bash
|
||||||
git clone https://github.com/tbuss/MMM-Wordpress.git
|
git clone https://github.com/tbuss/MMM-Wordpress.git
|
||||||
cd MMM-Wordpress
|
cd MMM-Wordpress
|
||||||
npm install
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
# Config
|
||||||
|
|
||||||
|
Put this in your config.js
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
module: 'MMM-Wordpress',
|
||||||
|
position: 'bottom_bar', // or any other position
|
||||||
|
config: {
|
||||||
|
updateInterval: 10*60*1000, // 10 minutes
|
||||||
|
url: 'https://www.your_wordpress.url',
|
||||||
|
numberOfPosts: 5
|
||||||
|
}
|
||||||
|
},
|
||||||
|
```
|
@ -7,9 +7,11 @@ module.exports = NodeHelper.create({
|
|||||||
},
|
},
|
||||||
|
|
||||||
socketNotificationReceived: function(notification, payload) {
|
socketNotificationReceived: function(notification, payload) {
|
||||||
|
console.log('Notification!');
|
||||||
if (notification === 'GET_POSTS') {
|
if (notification === 'GET_POSTS') {
|
||||||
const { url, numberOfPosts } = payload;
|
console.log('Notification: GET_POSTS');
|
||||||
const apiUrl = `${url}/wp-json/wp/v2/posts?per_page=${numberOfPosts}`;
|
const { url, posts, numberOfPosts } = payload;
|
||||||
|
const apiUrl = `${url}/wp-json/wp/v2/${posts}?per_page=${numberOfPosts}`;
|
||||||
|
|
||||||
request.get(apiUrl, (error, response, body) => {
|
request.get(apiUrl, (error, response, body) => {
|
||||||
if (!error && response.statusCode == 200) {
|
if (!error && response.statusCode == 200) {
|
Reference in New Issue
Block a user