Gutenberg: [ Latest Posts ] Iterations to version 2

Created on 5 Feb 2020  路  22Comments  路  Source: WordPress/gutenberg

The LatestPosts block is one of the first blocks in Gutenberg and, also, one of the most important blocks for fast and easy full page building. This block has been iterated on from launch and in its current state can offer basic functionality for post listing pages.

@melchoyce outlined in #1594 the improvements which the LatestPosts block needed in Jun 2017 and today, in February 2020, that list is almost complete - pending one exception: displaying featured images.

Given the past iteration plan is done and that in the past three years the block gathered new ideas I propose this issue as an overview issue for new features that can be added into a, let's call it, a LatestPosts version 2.

This version 2 of LatestPosts should include:

  • Implement the LatestPosts block as a variation of the Query block (issue: #24521)
  • Featured image support, in its own sidebar section (issue: #17472, pr: #17151)
  • Featured image caption (see Homepage Articles by Newspack)
  • Featured image link (issue: #21530, pr: #24548)
  • Whole block caption (see Homepage Articles by Newspack)
  • More default block styles, especially needed once we add featured image (see Homepage Articles by Newspack)
  • Featured image alignment (see Homepage Articles by Newspack)
  • Show author in posts (issue: #17681, pr: #16169)
  • Filter posts by tags and other taxonomies (issue: #13027, PR - tags: #19755)
  • Filter posts by author (PR: #16169)
  • Allow listing all CPTs, default to post (issue: #9013, PR: #20831)
  • Multiple categories support PR: #20781 (see Homepage Articles by Newspack)
  • Sort by comment number (issue: #22002)

August, 12, 2020 Edit: added on the list of tasks migrating the LP block to become a variation of the Query block.

There are a couple of things to keep in mind when developing for the LatestPosts
block, version 2:

  • With the advent of Full Site Editing there have been introduced a series of "Post Blocks", a set of blocks that can be used to describe and build a whole post in the context of a site page. These post blocks can be used to compose a full post and then display it in a loop.

    The current implementation of LatestPosts uses custom HTML to create the post structure in the loop. Optionally, if development of the LatestPosts version 2 takes a lot of time and the post blocks mature, we could implement the loop using these new blocks.

  • The more filtering features we add to the LatestPosts block the more it looks like a Queryblock, a block which doesn't exist yet but which could exist at some point (see issue: #2662 and prs: #20106, #3198 taking the first steps in this direction).

    This block would be a generalization of a block that can allow a user to visually customize a WP_Query for a specific post loop, ideally offering all the options that WP_Query does. We can either end up with both LatestPosts and Query blocks and use them when appropriate, or we can, at some point in the future, evolve LatestPosts into a more generic, all encompassing, Query block.

Are you a new contributor?

This issue itself is big but it can, and will, be divided into smaller issues (some already exist). Trying to implement any of the missing features above is a great way to start contributing to Gutenberg with code. Also reviews of open PRs, suggestions and perspectives on open issues, are of great value as well. If you want to help but have questions, please leave a comment here so we can discuss what would be the best next step for you.


TL:DR;
Having a more feature complete LatestPosts block is a priority for this year as it is a cornerstone of giving users easy control on post listings when working with Full Site Editing on their pages. Therefore jump in and let's build the best and most user friendly post listing block in the world!

Needs Dev [Block] Latest Posts [Type] Overview

Most helpful comment

I've implemented a method to add multiple categories support. I've been working on the current LatestPosts but of course it will be able to lift it to any component. Here's a gif that shows the behaviour:
ezgif-3-7d71cf866e74
And here's my commit.

Is the plan to build a new LatestPosts component and toss the current or should we continue with the existing?

All 22 comments

I'm a new contributor but I've been hacking and developing in Gutenberg for over a year for our clients. Including custom posts blocks.

Feel free to push me in the right direction or assign me to anything appropriate!

I recommend checking out the Custom Post Type block from Getwid. It is essentially a latest posts block for any post type. The template used for each of the posts in the list can be modified using the block editor. In other words, you can use the block editor to build a latest post item template, and then choose that template in the display settings of the block.

It was certainly one of the most creative uses of the block editor I've seen in a plugin, and I think it could be used as inpsiration for something similar in core.

I think instead of trying to add more and more features and toggles to this block, we should focus on the Query block which will have similar results with more flexibility.

@youknowriad while it is true that the QueryBlock is upcoming, it is still something new which serves to a second step on this project, which is to refactor the LatestPosts block to be modular, to reuse existing blocks and make use of the context provided by a QueryBlock.

However we can still add the features to the block and when we refactor they'll be there already. otherwise the block and the experience will probably lag a lot more time. Indifferent of the QueryBlock, at least to my understanding, LatestPosts will not be replaced, just refactored to use QueryBlock right?

I kind of agree with @youknowriad that adding a lot of features to this block feels overwhelming from an experience point of view. I think there could be a balance between adding new features and not adding any. For example:

Featured image caption (see Homepage Articles by Newspack)
Whole block caption (see Homepage Articles by Newspack)
More default block styles, especially needed once we add featured image (see Homepage Articles by Newspack)

I think you could add those - more styling could also solve alignment by offering it as an option.

Thanks for creating this issue Andrei! @draganescu

I think we can portion it out a little more. Into additional stages.
Version 2 could add some features. Get those in. Test it out.
Then create a version 3.

I am myself these days using this Latest Post block plugin: https://wordpress.org/plugins/post-type-archive-mapping/

I admit that I haven't delved into the specific code for post-excerpt block and it may be too late to do it, but why not build Latest Posts from it?

Howdy @skorasaurus what do you mean build LatestPosts from PostExcerpt. To me they seem to be serving very differen usecases.

@karmatosed @paaljoachim @youknowriad all the items in this overview are meant for exploration, some have their own issues, some don't. Particularly those items that don't even have open issues are far from implementation. Design and conceptual phases will push them farther in time.

Until then, the items that are possible now and which fit easily in the UX of the current block should be worked on within the possibilities that exist, right? Then, in the mean time, while new APIs make the LatestPosts block a good candidate for refactoring, items which will be implemented later will be so using the refactored and more modern block.

This basically means that this overview issue is a conversation starter for many of the items it contains, less so an implementation directive.

@draganescu I presume he means that the Latest Posts block could be built using a template for each of the post items, and you could build that template using the Post Title, Post Excerpt, and Post Meta blocks. The Custom Post Type block in Getwid uses a similar approach.

Yes I am exploring building LatestPosts with composed post blocks but there are some limitations currently. See #19685 .

I've implemented a method to add multiple categories support. I've been working on the current LatestPosts but of course it will be able to lift it to any component. Here's a gif that shows the behaviour:
ezgif-3-7d71cf866e74
And here's my commit.

Is the plan to build a new LatestPosts component and toss the current or should we continue with the existing?

Hey @Ringish

It is awesome that you are working on multiselect! What about creating a PR?
I made a Add multi select drop down issue some time ago: https://github.com/WordPress/gutenberg/issues/17009
It will be great to have multiselect included in Gutenberg that can be used for instance with Categories etc.

Would it be possible to allow Latest Posts block to curate specific posts from a Post Picker/Link Control vs a dynamic query e.g. manual curation of homepage posts hero/featured posts?

@rickalee Is that related to the Latest Posts or should it be an own component? What's your thoughts @draganescu?

Howdy @rickalee yes we need that too! It might be better suited for a stand alone block though?

With the incoming QueryBlock we will be able to build such specific post items queries and display them in custom hero or featured blocks. Until then we can either wait or build separate blocks for manual curation. Otherwise we could really bloat this block.

The post ID based filter can be added but the hero or featured and other style of presentation get a bit out of the scope of "LatestPosts" :) Pherhaps like @karmatosed suggested this will either evolve into a more generic "Posts" block or be broken into many more specific ones (e.g. a hero post block, a featured posts block, a truely "latest" posts block, an author archives block etc.

There's quite a bit going on here. My recommendation is to make some issues with specific ideas to pursue to move forward. It would also be good to try some of this with the upcoming query block instead.

Howdy @MichaelArestad ! The issue has the label [ Type ] Overview and also there is a link for each of the items in the description to already open issues and latest PRs.

A few of the proposed issues for phase 2 are still open for discussion, and the point is if there is no issue linked, no one is interested enough in that feature.

Is the query block ready and merged?

One thing that would be good to have is the ability to show top commented posts in the latest post block.

This would be a filter - sort by comment number.

@dingo-d could you open an issue for this suggestion?

Now that we have a merged Query Block (#22199) we could start exploring doing a feature freeze here and copying all the current LP block features to a new one implemented using the new Query Block.

Yeah, maybe the Latest Posts block exposed in the inserter could just be a block variation of the Query block!

Was this page helpful?
0 / 5 - 0 ratings