Skip to content

Instantly share code, notes, and snippets.

@yoren
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoren/240c944298ee8666d577 to your computer and use it in GitHub Desktop.
Save yoren/240c944298ee8666d577 to your computer and use it in GitHub Desktop.
AngularJS WordPress Theme: Using Slug In Permalink To Get Post
<h1 ng-bind-html="post.title"></h1>
<div ng-bind-html="post.content"></div>
<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>
//...
//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