Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suite of Post Blocks #15623

Open
mtias opened this issue May 14, 2019 · 10 comments

Comments

@mtias
Copy link
Contributor

commented May 14, 2019

We currently offer a "latest posts" blocks with some configuration options which can be pretty nice for setting up homepages with some dynamic content arranged in different sort of grids and lists. There is also some ongoing work to include showing a featured image and the post excerpt as features than can toggled on the block settings.

However, it is clear such a block won't scale to offer all the flexibility that a proper post loop on a theme provides — it's not just showing elements (date, author, and so on) but also their positioning — nor the best editing experience either compared to more granular blocks.

What would be interesting is to explore a "Post" block that works as the wrapper for the post_ID context, and which contains an inner blocks area with several available child blocks:

  • Post Title
  • Post Author
  • Post Date
  • Post Excerpt
  • Featured Image
  • Post Content
  • Categories
  • Tags

This would allow displaying a "post" element in any context and with full flexibility.

wp:post { id: 1 }
    wp:post-title
    wp:featured-image
    wp:post-excerpt

Furthermore, this block can support templates, so on insertion it can offer a few defaults (just post title, post title and excerpt, featured image to the side, etc).

Starting with a single post would allow us to determine how the child blocks should be structured. By having each element be a child block, we can also expand on the configuration options much more elegantly: the date format display would be easier to connect, the excerpt can offer to customize the number of words and the trailing cutoff, the image can have specific settings, and so on.

If this proves convenient, we can then look at a more general purpose Query block that would allow to control the query parameters and then use the "post" block for display. This could be super useful for themes to build sophisticated static pages with dynamic content but full control over layout and content.

image

@richtabor

This comment has been minimized.

Copy link

commented Jun 28, 2019

Just for clarification, that screenshot is of three Post blocks using the Columns block? Or a block that adds posts based on a templateOption selection (using this Post block)? Just wrapping my head around it :)

@youknowriad

This comment has been minimized.

Copy link
Contributor

commented Jun 28, 2019

Or a block that adds posts based on a templateOption selection (using this Post block)?

This one I think. The parent block being something like a "repeater" block.

Edit: The block can probably support both.

@mtias

This comment has been minimized.

Copy link
Contributor Author

commented Jun 28, 2019

The parent block being something like a "repeater" block.

Yes, I figure we'd end up with a "Loop" container that defines and handles the query options. Inside, it would use a Post block with a specific template/layout.

That's why I think we can converge on the problem by enhancing the Latest Posts block and implementing these more granular sets of post child blocks.

@getdave

This comment has been minimized.

Copy link
Contributor

commented Jun 29, 2019

So is the idea that this is a single block for now then later it might be combined with a post list block to provide the "item" for the list? It could also function as a stand alone block foe rendering a single post.

Practically if used within post listing, how would this block receive the post id context? Would it require the parent list block to dispatch to update the attrs of the child post blocks?

It would be great to see this come to life. Do we see the individual sub blocks (eg: post meta block) living at the top directory level a la the single column block?

@mtias

This comment has been minimized.

Copy link
Contributor Author

commented Jul 1, 2019

In the context of loops this block would work rather like a template.

@luisherranz

This comment has been minimized.

Copy link
Contributor

commented Jul 23, 2019

I love the idea of combining a Query block with Post blocks. I've seen so many custom-coded pages over the years whose only purpose was to output posts from a custom query that I'm shedding a tear right now.

Some questions:

  • Have you taken a look at what the Newspack team is doing? It looks like they are working in a similar block for their theme, although it is not as flexible: https://videopress.com/v/xDLCB0QV
  • Would this support pagination? If so, how would it work?
  • Would it be possible to include the list of posts in the REST API response?
    (Maybe add an option to the Query block that adds a _link which works with _embed).
@mtias

This comment has been minimized.

Copy link
Contributor Author

commented Jul 24, 2019

Thanks for chiming in @luisherranz

I saw that block, it bundles a lot of customization options in a single block (similar to "Latest Posts" in core), which is what I'm looking forward to exploring here as a more flexible and usable alternative.

Related: #16283

Would this support pagination? If so, how would it work?

Pagination as slideshow-style or as navigating to another URL?

@luisherranz

This comment has been minimized.

Copy link
Contributor

commented Jul 25, 2019

Well, I was actually thinking about pagination to another URL, like /custom-list/page/2.

I know that's probably way more complex than your original idea, so it's just a thought... But it could solve a pattern that has not been easy to solve in the past: lists of posts based on custom queries.

Some examples that require code right now but could be solved with a Paginated Query block:

  • Posts from some category, but excluding an author or tag.
  • Posts from two categories merged together.
  • Products with a discount greater than X%, ordered by the discount.
  • Gadgets containing a Review block, ordered by their review score.
  • Restaurants that belong to a certain city, ordered by the number of comments.

Besides, users would have much more freedom when choosing the way those posts are displayed thanks to the child blocks.

@mtias

This comment has been minimized.

Copy link
Contributor Author

commented Jul 26, 2019

Oh, this would be part of work on dynamic pages that map to the template hierarchy and includes archive pagination. Those would have the concept of main query / loop or something similar, but is a bit beyond the scope of this one.

@luisherranz

This comment has been minimized.

Copy link
Contributor

commented Jul 26, 2019

Glad to hear there are plans for that :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.