Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

Conversation

@rmccue
Copy link
Member

@rmccue rmccue commented Sep 18, 2015

Rather than linking to wp/v2/media?post_parent=<id>, we should be linking directly to the featured image, with a secondary link out to the former.

Fixes #1476.

@rmccue rmccue added this to the 2.0 Beta 5 milestone Sep 18, 2015
@rmccue
Copy link
Member Author

rmccue commented Sep 18, 2015

I was thinking we should maybe use a different relation for attached vs featured; maybe http://v2.wp-api.org/featured? In lieu of that, I've changed it to have featured: true

@WP-API/amigos Thoughts?

@scottopolis
Copy link

Could we add the post_thumbnail src somewhere? It should be part of the embedded object so we can display a list of posts with thumbnails without going to the /media endpoint separately. For example:

$links['http://v2.wp-api.org/attachment'] = array();
    if ( $featured_image = get_post_thumbnail_id( $post->ID ) ) {
        $image_url = rest_url( 'wp/v2/media/' . $featured_image );
        $links['http://v2.wp-api.org/attachment'][] = array(
            'href'       => $image_url,
            'embeddable' => true,
            'featured'   => true,
            'post_thumbnail'  => wp_get_attachment_image_src( $featured_image )[0]
        );
    }

@rachelbaker
Copy link
Member

@rmccue Any thoughts on @scottopolis's request?

Could we add the post_thumbnail src somewhere?

@rmccue
Copy link
Member Author

rmccue commented Sep 22, 2015

@scottopolis Not sure what you're wanting here? The source_url is exposed; guessing you mean media_details.sizes should be exposed too?

@rmccue
Copy link
Member Author

rmccue commented Sep 22, 2015

@rachelbaker If we do make a change around the image URLs, it needs to be in the embedded data, not on the link itself, so shouldn't affect this PR. :)

@scottopolis
Copy link

@rmccue @rachelbaker Yes, we need post thumbnail sizes, not just the source url in the _embed object. This would be just the post thumb, not all attachments.

Example use case would be listing posts in a mobile app, so I can display the 150x150px post thumbnail for each post.

@scottopolis
Copy link

Here is the pull request related to my comments #1582

rachelbaker added a commit that referenced this pull request Sep 23, 2015
@rachelbaker rachelbaker merged commit eb8beaa into develop Sep 23, 2015
@rachelbaker
Copy link
Member

Merged #1563

@joehoyle
Copy link
Member

I think we should have gone with a different relation here, I think having it part of the attachments relation is a bit cumbersome to work with for clients. It looks like that discussed wasn't picked up however.

@danielbachhuber danielbachhuber deleted the fix-featured-image-links branch October 28, 2015 12:25
@danielbachhuber
Copy link
Member

I think having it part of the attachments relation is a bit cumbersome to work with for clients

Why so?

@joehoyle
Copy link
Member

Looking at the response in http://demo.wp-api.org/wp-json/wp/v2/posts/162?_embed, there's no way to hardcode the path to the featured image link for embedded item, you'd have to do a filter on the http://v2.wp-api.org/attachment relation to only get ones with embedded => true.

If you want to get the data from embedded, there's no way to programmatically know which embedded attachment is the featured image, short of cross referencing with the _links array, or blindly _embedded["http://v2.wp-api.org/attachment"][0]`.

I don't really understand the rational for the way we have it now, they are different relationships; it seems we are grouping the attachments with the featured image because they are the same resource type, which actually has little bearing on what the relationship is.

@danielbachhuber danielbachhuber changed the title Change featured image links Link directly to the featured image in a Post's links Nov 12, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants