wp-angularjs
A WP-API Client for AngularJS.
Getting Started
$ npm install wp-angularjs --save
WP-Angular
Demo: http://miya0001.github.io/wp-angularjs/demo/
Requires
Recommended:
API Reference
<have-posts>
The havePosts
directive is a WordPress loop.
Attributes
Attribute | Type | Details |
---|---|---|
api-root | string | Root url of the API. e.g. http://example.com/wp-json/wp/v2 |
post-type | string | posts or pages or media or custom post type. |
per-page | number | The number of posts per page. Default is 10. |
offset | number | The number of post to displace or pass over. Default is 0. |
post-id | number | The ID of the post. |
filter | object | The object of the filter. |
Example
If you want to get single post, you can use post-id
.
You can pass filters to
WP_Query
through via the filter
argument.
<the-title>
Displays the post title of the current post.
This tag must be used within The <have-posts>
.
Attributes
Attribute | Type | Details |
---|---|---|
href | string | Specify a link URL like #/app/posts/:id . |
Example
Then:
Hello World
If you need a link to the post on your app. Please add href
as attribute.
Then:
Hello World
:id
is a placeholder of the post's id. You can use :slug
as post's slug too.
Then:
Hello World
<the-content>
Displays the post content of the current post.
This tag must be used within The <have-posts>
.
Example
Then:
Hello World
<the-post-thumbnail>
Displays the post thumbnail of the current post.
This tag must be used within The <have-posts>
.
Attributes
Attribute | Type | Details |
---|---|---|
size | string | Size of the post thumbnail. Default is full . |
href | string | Specify a link URL like #/app/posts/:id . |
Example
Then:
<div class="the-post-thumbnail"><img src="http://example.com/image.jpg"></div>
Uses size
attribute.
Then:
<div class="the-post-thumbnail"><img src="http://example.com/image.jpg"></div>
If you need a link to the post on your app. Please add href
as attribute.
Then:
:id
is a placeholder of the post's id. You can use :slug
as post's slug too.
Then:
<the-id>
Displays the ID of the current post.
This tag must be used within The <have-posts>
.
Example
<the-id></the-id>
Then:
<div class="the-id">123</div>
<the-excerpt>
Displays the excerpt of the current post.
This tag must be used within The <have-posts>
.
Example
Place the code like following into your HTML.
<the-excerpt></the-excerpt>
Then you will get like following.
<div class="the-excerpt"><p>Hello World.</p></div>
<the-date>
Displays the date of the current post.
This tag must be used within The <have-posts>
.
Attributes
Attribute | Type | Details |
---|---|---|
format | string | See https://docs.angularjs.org/api/ng/filter/date |
Example
Place the code like following into your HTML.
<the-date></the-date>
Then you will get like following.
<div class="the-date">2016-02-16 13:54:13</div>
You can set format string like following. See https://docs.angularjs.org/api/ng/filter/date.
<the-date format="yyyy/MM/dd"></the-date>
Then you will get like following.
<div class="the-date">2016-02-16</div>
Creates your custom template tag
// Registers your module, you should import `wp`.var myapp = angular; // Creates a `<my-permalink></my-permalink>` as custom template tag.// If you place it in your HTML,// then you can get `<a href="#!/post/123">Hello</a>`.myapp;
Enables Infinite Scroll
Please load ngInfiniteScroll like following.
Add infinite-scroll
as a dependency.
angular;
That's it.
How to contribute
$ npm install
Run testing.
$ npm test
Build js/wp-angular.min.js
.
$ npm run build
Build documentation.
$ npm run docs