Hi I’m following this tutorial about wordpress + ionic 3 integration:
and all works fine.
But I would like to add to the post also the featured image to display in the homepage. I’ve read different tutorials about this but the 100% of them is for different ionic version and the code it’s so many different from the code that I have (from the tutorial).
I’m already taking the list of the post in my homepage.
This is a snippet from homepage.ts
[...]
if(!(this.posts.length > 0)){
let loading = this.loadingCtrl.create();
loading.present();
this.wordpressService.getRecentPosts(this.categoryId) //Se cambio questo mettendo un numero come id della categoria, mi mostra solo quella categoria.
.subscribe(data => {
for(let post of data){
post.excerpt.rendered = post.excerpt.rendered.split('<a')[0] + "</p>";
this.posts.push(post);
}
loading.dismiss();
});
}
This is home.html where I would like to show the featured image
[...]
<ion-card-content >
<ion-card-title id="post_title" [innerHTML]="post.title.rendered"></ion-card-title> <!--Titolo-->
<p id="post_text" [innerHTML]="post.excerpt.rendered"></p> <!--Corpo del testo-->
<img [src]="post.featured_media.embed">
</ion-card-content>
and this is the code that retrieve the posts using the api, in a service that I made wordpress.service.ts
getRecentPosts(categoryId:number, page:number = 1){
//if we want to query posts by category
let category_url = categoryId? ("&categories=" + categoryId): "";
return this.http.get(
Config.WORDPRESS_REST_API_URL
+ 'posts?page=' + page
+ category_url)
.map(res => res.json());}
How can I show also the featured image? I read somewhere that I should do another get request, but I don’t know how to start :S
If more code is needed tell me.
Thank you in advance.