Last active
August 29, 2015 14:14
-
-
Save yoren/240c944298ee8666d577 to your computer and use it in GitHub Desktop.
AngularJS WordPress Theme: Using Slug In Permalink To Get Post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1 ng-bind-html="post.title"></h1> | |
<div ng-bind-html="post.content"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<search-form></search-form> | |
<ul> | |
<li ng-repeat="post in posts"> | |
<a href="{{post.slug}}" ng-bind-html="post.title"></a> | |
<div ng-bind-html="post.content"></div> | |
</li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
//Config the route | |
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) { | |
//... | |
.when('/:slug', { | |
templateUrl: myLocalized.partials + 'content.html', | |
controller: 'Content' | |
}); | |
}]); | |
//... | |
//Content controller | |
app.controller('Content', ['$scope', '$http', '$routeParams', function($scope, $http, $routeParams) { | |
$http.get('wp-json/posts/?filter[name]=' + $routeParams.slug).success(function(res){ | |
$scope.post = res[0]; | |
}); | |
}]); | |
//... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment