【问题标题】:How can i fetch another wordpress post to my site's homepage?如何获取另一个 wordpress 帖子到我网站的主页?
【发布时间】:2019-03-26 22:14:52
【问题描述】:
已编辑:我的问题是,我如何在我自己的网站主页上列出另一个网站的 rss 提要,这样当访问者点击这些列表中的任何一个时,它会将访问者引导到我从中获取这些 rss 提要的网站?
【问题讨论】:
-
欢迎来到 Stack Overflow!其他用户将您的问题标记为低质量和需要改进。我重新措辞/格式化您的输入,使其更容易阅读/理解。请查看我的更改以确保它们反映您的意图。但我认为你的问题仍然无法回答。 你现在应该edit你的问题,包括你自己的努力(见help me is not a question)。如果您对我有其他问题或反馈,请随时给我留言。
标签:
wordpress
post
fetch-api
auto
【解决方案1】:
您可以使用 emberjs 从 wordpress 获取帖子。
App.js
App = Ember.Application.create();
App.Router.map(function() {
this.resource('about');
this.resource('posts', function() {
this.resource('post', {path: ':post_id'});
});
});
App.PostsRoute = Ember.Route.extend({
model: function() {
return $.getJSON('http://wordpresssite/api/get_recent_posts/?callback=?').then(function(data) {
return data.posts.map(function(post) {
post.body = post.content;
return post
});
});
}
});
App.PostRoute = Ember.Route.extend({
model: function(params){
return posts.findBy('id', params.post_id);
}
});
App.PostController = Ember.ObjectController.extend({
isEditing: false,
actions: {
edit: function(){
this.set('isEditing', true);
},
doneEditing: function() {
this.set('isEditing', false);
}
}
});
Ember.Handlebars.helper('format-date', function(date){
return moment(date).fromNow();
});
var showdown = new Showdown.converter();
Ember.Handlebars.helper('format-markdown', function(input) {
return new Handlebars.SafeString(showdown.makeHtml(input));
});
index.html
<script type="text/x-handlebars">
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="#">Bloggr</a>
<ul class="nav">
<li>{{#link-to 'posts'}}Posts{{/link-to}}</li>
<li>{{#link-to 'about'}}About{{/link-to}}</li>
</ul>
</div>
</div>
{{outlet}}
</script>
<script type="text/x-handlebars" id="posts">
<div class='container-fluid'>
<div class='row-fluid'>
<div class='span3'>
<table class='table'>
<thead>
<tr><th>Recent Posts</th></tr>
</thead>
{{#each}}
<tr><td>
{{#link-to 'post' this}}
{{title}} <small class='muted'>by {{author.name}}</small>
{{/link-to}}
</td></tr>
{{/each}}
</table>
</div>
<div class="span9">
{{outlet}}
</div>
</div>
</div>
</script>
<script type="text/x-handlebars" id="post">
{{#if isEditing}}
{{partial 'post/edit'}}
<button {{action 'doneEditing'}}>Done</button>
{{else}}
<button {{action 'edit'}}>Edit</button>
{{/if}}
<h1>{{title}}</h1>
<h2>by {{author.name}} <small class='muted'>({{format-date date}})</small></h2>
<hr>
<div class='intro'>
{{format-markdown excerpt}}
</div>
<div class='below-the-fold'>
{{format-markdown body}}
</div>
</script>
<script type="text/x-handlebars" id="post/_edit">
<p>{{input type="text" value=title}}</p>
<p>{{input type="text" value=excerpt}}</p>
<p>{{textarea value=body}}</p>
</script>
<script type="text/x-handlebars" id="about">
<div class='about'>
<p>This is my first Ember.js website. Going to see how it all of this works</p>
</div>
</script>
<script src="js/libs/handlebars-1.0.0.js"></script>
<script src="js/libs/ember-1.0.0.js"></script>
<script src="js/app.js"></script>
示例希望对您有所帮助。