Skip to content

Commit

Permalink
Theming with WP REST API - Part 09 - Previous Next Post
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Doric committed Apr 7, 2016
1 parent aeb1bc3 commit a2ca594
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 12 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,25 @@ function prepare_rest($data, $post, $request){
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$thumbnail300x180 = wp_get_attachment_image_src( $thumbnail_id, '300x180' );
$thumbnailMedium = wp_get_attachment_image_src( $thumbnail_id, 'medium' );
$full = wp_get_attachment_image_src( $thumbnail_id, 'full' );

//Categories
$cats = get_the_category($post->ID);

//next/prev

$nextPost = get_adjacent_post(false, '', true );
$nextPost = $nextPost->ID;

$prevPost = get_adjacent_post(false, '', false );
$prevPost = $prevPost->ID;

$_data['fi_300x180'] = $thumbnail300x180[0];
$_data['fi_medium'] = $thumbnailMedium[0];
$_data['full'] = $full[0];
$_data['cats'] = $cats;
$_data['next_post'] = $nextPost;
$_data['previous_post'] = $prevPost;
$data->data = $_data;

return $data;
Expand Down
10 changes: 9 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,20 @@
<h2>{{ post[0].title.rendered }}</h2>

<div class="image">
<img v-bind:src="post[0].fi_300x180">
<img v-bind:src="post[0].full">
</div>

<div class="post-content">
{{{ post[0].excerpt.rendered }}}
</div>

<a v-on:click="getThePost(post[0].next_post)" v-if="post[0].next_post" class="post-nav next">
<span class="icon-right"></span>
</a>

<a v-on:click="getThePost(post[0].previous_post)" v-if="post[0].previous_post" class="post-nav prev">
<span class="icon-left"></span>
</a>
</div>

</template>
Expand Down

0 comments on commit a2ca594

Please sign in to comment.