我正在尝试使用 WordPress WP-API 实现 Bootstrap UI Angular Carousel。我很好奇如何将“幻灯片”与“帖子”联系起来
演示 HTML 是...
<div class="carousel" ng-controller="CarouselDemoCtrl">
<div style="height: 305px">
<carousel interval="myInterval">
<slide ng-repeat="slide in slides" active="slide.active">
<img ng-src="{{slide.image}}" style="margin:auto;">
<div class="carousel-caption">
<h4>Slide {{$index}}</h4>
<p>{{slide.text}}</p>
</div>
</slide>
</carousel>
</div>
</div>
javascript单独工作正常。例如,我可以使用 ng-repeat 来显示帖子。示例 ng-repeat="slide in slides" 显示演示幻灯片。
angular.module('app', ['ngRoute', 'ui.bootstrap' ])
// Retrieves Posts
.controller('Main', function($scope, $http, $routeParams){
$http.get('wp-json/posts/').success(function(res){
$scope.posts = res;
});
$http.get('wp-json/media/').success(function(res){
$scope.media = res;
});
})
示例 Bootstrap 实现是...
//Bootstrap Carousel
.controller('CarouselDemoCtrl', function ($scope) {
$scope.myInterval = 5000;
var slides = $scope.slides = [];
$scope.addSlide = function() {
var newWidth = 600 + slides.length + 1;
slides.push({
image: 'http://placekitten.com/' + newWidth + '/300',
text: ['More','Extra','Lots of','Surplus'][slides.length % 4] + ' ' +
['Cats', 'Kittys', 'Felines', 'Cutes'][slides.length % 4]
});
};
});
我将如何实现连接幻灯片和帖子的东西?这样,它会抓取例如帖子中的特色图片并将其插入幻灯片吗?