编辑:我的问题是,我如何在我自己站点的主页上列出另一个网站的rss feed,以便当访问者单击这些列表中的任何一个时,它将访问者定向到我从中获取这些rss feed的网站?
答案 0 :(得分:0)
您可以使用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>
示例,希望对您有所帮助。