How I Built It: Related Posts Block ![rw-book-cover](https://api.mightyshare.io/v1/MSf5qyK1adJRn0k9/6d39dc5a483e6a3100c0ce5914d30f9782fb05ed109aa951275aee4ad59e007b/jpeg?cache=true&height=630&width=1200&template=standard-2&template_values=%5B%7B%22name%22%3A%22google_font%22%2C%22google_font%22%3A%22Play%22%7D%2C%7B%22name%22%3A%22logo_width%22%2C%22text%22%3A%22%22%7D%2C%7B%22name%22%3A%22primary_color%22%2C%22color%22%3A%22%2355e2e9%22%7D%2C%7B%22name%22%3A%22logo%22%2C%22image_url%22%3A%22https%253A%252F%252Fjacobmartella.me%252Fwp-content%252Fuploads%252F2024%252F01%252Flogo-text-light.png%22%7D%2C%7B%22name%22%3A%22background%22%2C%22image_url%22%3A%22https%253A%252F%252Fjacobmartella.me%252Fwp-content%252Fuploads%252F2024%252F02%252Frelated-posts-block.jpg%22%7D%2C%7B%22name%22%3A%22title%22%2C%22text%22%3A%22How%2520I%2520Built%2520It%253A%2520Related%2520Posts%2520Block%22%7D%2C%7B%22name%22%3A%22description%22%2C%22text%22%3A%22%22%7D%5D&page=https%3A%2F%2Fjacobmartella.me%2Fweb-development%2Fblock-editor%2Fhow-i-built-it-related-posts-block) ๐Ÿ”— **Source:** [How I Built It: Related Posts Block](https://jacobmartella.me/web-development/block-editor/how-i-built-it-related-posts-block/) > [!note]+ Document Notes > tags: [wordpress-blocks, related-posts, gutenberg-development] > author: Jacob Martella > source: jacobmartella.me > reference: https://jacobmartella.me/web-development/block-editor/how-i-built-it-related-posts-block/ > date created: {{date:YYYY-MM-DD}} {{time:HH:mm}} > > # ๐Ÿท๏ธ Title: How I Built It: Related Posts Block > <!-- deep-read:sections start --> ## ๐Ÿงญ Table of Contents - [๐Ÿ“ Summary](#-summary) - [๐Ÿ“– Main Content](#-main-content) - [๐Ÿ—’๏ธ Notes](#๏ธ-notes) - [๐Ÿ“š References](#-references) - [๐Ÿ—ฃ๏ธ Paraphrase](#๏ธ-paraphrase) - [๐Ÿ“ฐ Newsletter](#-newsletter) - [โœ… Action Items](#-action-items) - [๐Ÿงช Hypotheses](#-hypotheses) - [๐Ÿ“Š Methodology](#-methodology) - [โ“ Questions](#-questions) - [๐Ÿ”ฎ Future Research](#-future-research) - [๐Ÿ’ก Implications](#-implications) - [๐Ÿง  Learning Styles Assessment](#-learning-styles-assessment) - [๐Ÿ“Š Accessibility Assessment](#-accessibility-assessment) - [๐ŸŒ DEIB Assessment](#-deib-assessment) - [โœ… Logical Validity](#-logical-validity) - [๐Ÿ›ก๏ธ DARVO Analysis](#-darvo-analysis) - [๐ŸŽฏ Conclusion](#-conclusion) ## ๐Ÿ“ Summary - Jacob Martella built a Related Posts block for the Crosswinds Blocks plugin because WordPress core doesn't include this functionality. - The project involved studying the Query Loop and Post Template blocks from Gutenberg core for inspiration. - The solution provides customizable related post display with grid options and works across all post types. - Implementation required both editor-side React components and front-end PHP templating. - The block now supports custom taxonomies per post type through plugin settings. ## ๐Ÿ“– Main Content Jacob Martella created a Related Posts block to solve the gap in WordPress core block functionality. Related posts help retain website visitors by suggesting relevant content, but this feature isn't available as a core block or easily achievable with the Query Loop block. ### Technical Implementation Approach The development process involved two main phases: **Editor Implementation**: Martella studied the post template block in the Gutenberg repository to understand React patterns like `memo` and complex state management. He adapted this code for the Related Posts block, adding inspector controls for post count and column layout. **Front-end Rendering**: The PHP template adapted the Single Content block's approach, modifying the query to pull related posts based on current post tags in random order. CSS classes handle the responsive grid layout. ### Post Type Extension Initially limited to posts, version 1.1 expanded support to all post types. This required creating a settings interface where users can map taxonomies to post types, since different content types use different taxonomies for relationships. The block queries posts from the same post type using the configured taxonomy terms from the current post, ensuring relevant suggestions across custom post types. ## ๐Ÿ—’๏ธ Notes - WordPress core deliberately excludes related posts functionality, placing it in plugin territory - The Query Loop block cannot easily replicate related post functionality - React components like `memo` were initially challenging but became clearer with experience - Copy-paste approach from core blocks provided a working foundation - Custom taxonomy mapping solved the multi-post-type challenge - Grid layout uses CSS classes with configurable column counts - Random ordering prevents repetitive suggestions ## ๐Ÿ“š References - [Crosswinds Blocks plugin](https://jacobmartella.me) - [Gutenberg GitHub repository](https://github.com/WordPress/gutenberg) - [WordPress Query Loop block documentation](https://wordpress.org/documentation/) ## ๐Ÿ—ฃ๏ธ Paraphrase A WordPress developer needed related posts functionality for block themes but found no core solution. He studied how WordPress's post template block works in React, then adapted that pattern to create a custom Related Posts block. The initial version worked for blog posts only, querying by tags. Later updates added support for all post types by letting users configure which taxonomy to use per content type. The solution combines React for the editor experience with PHP for front-end rendering, providing grid layout options and random post ordering. ## ๐Ÿ“ฐ Newsletter **Building Custom WordPress Blocks: Related Posts Edition** Missing related posts in your block theme? Jacob Martella's journey building a Related Posts block for the Crosswinds Blocks plugin offers valuable insights for WordPress developers. He dove deep into Gutenberg's post template block source code, learned React patterns like `memo`, and created a fully customizable solution. The block supports grid layouts, custom post types, and configurable taxonomiesโ€”filling a gap that core WordPress intentionally leaves to plugins. Perfect reading for anyone building custom blocks or wondering why some "obvious" features aren't in core. [Read the full breakdown](https://jacobmartella.me/web-development/block-editor/how-i-built-it-related-posts-block/) and check out the [Crosswinds Blocks plugin](https://jacobmartella.me) for implementation examples. ## โœ… Action Items #### WordPress - **Core**: N/A - Related posts deliberately excluded from core - **Plugins**: Document patterns for related content blocks in developer handbook - **Community**: Create block development workshops focusing on Query Loop extensions #### DevRel - Developer education: Workshop on adapting core block patterns for custom use cases - Documentation: Create guides for reading and understanding Gutenberg source code - Community engagement: Showcase community block development success stories #### Community - Contributors: Develop block development mentorship for intermediate React patterns - Maintainers: Create reusable patterns for common block functionality gaps ## ๐Ÿงช Hypotheses - Related posts blocks improve user engagement and session duration on WordPress sites - Copying core block patterns provides more stable foundations than building from scratch - Custom taxonomy mapping is essential for related content across different post types - Developer comfort with React correlates with successful custom block development ### ๐Ÿ“Š Methodology - A/B testing related posts vs. no related posts for engagement metrics - Developer surveys on block development learning paths and pain points - Performance analysis of query-based blocks on large content sites ### โ“ Questions - How do related posts impact actual user behavior versus perceived engagement? - What's the optimal number of related posts for different content types? - Should WordPress core reconsider including basic related posts functionality? ### ๐Ÿ”ฎ Future Research - Machine learning approaches for better content relationship detection - Performance optimization for related content queries at scale - User experience patterns for related content display across devices ### ๐Ÿ’ก Implications - **Practice**: Custom blocks can fill core functionality gaps effectively - **Education**: Reading core code is valuable for intermediate block developers - **Plugin development**: Settings screens enable flexible block behavior across use cases ### ๐Ÿง  Learning Styles Assessment Reading level: College level (technical implementation details, React terminology) #### ๐Ÿ‘€ Visual learners - Present: Code structure descriptions, grid layout concepts - Improve: Flowcharts of query logic, before/after block editor screenshots #### ๐Ÿ”Š Aural learners - Present: Written walkthrough of development process - Improve: Screencast of block development process, code explanation videos #### ๐Ÿ—ฃ๏ธ Verbal learners - Present: Clear explanations of React concepts, step-by-step process - Improve: Glossary of technical terms, analogies for complex concepts #### ๐Ÿงฉ Kinesthetic learners - Present: Implementation steps, hands-on development approach - Improve: Interactive code sandbox, step-by-step tutorial with checkpoints ### ๐Ÿ“Š Accessibility Assessment #### Screen reader semantics - Present: Clear heading structure, descriptive text - Improve: Code examples need better alt descriptions #### Keyboard navigation - Present: Standard blog post navigation - Improve: Skip links for code sections ### ๐ŸŒ DEIB Assessment #### Cultural breadth - Present: English-only content, US-centric examples - Improve: Multi-language block examples, global use cases #### Inclusive language - Present: Technical but accessible language - Improve: Define React/WordPress jargon consistently ### โœ… Logical Validity #### Strong reasoning - **Problem identification**: Clear gap in WordPress core functionality - **Solution approach**: Logical progression from studying existing patterns - **Implementation strategy**: Sensible division between editor and front-end concerns #### Tone of voice Conversational and honest, acknowledging learning challenges and imperfect approaches ("I'm going to be completely honest"). ### ๐Ÿ›ก๏ธ DARVO Analysis No DARVO patterns present - straightforward technical development narrative. ## ๐ŸŽฏ Conclusion Martella's Related Posts block demonstrates effective custom WordPress block development by studying and adapting core patterns. The project successfully fills a functionality gap while providing insights into React-based block development and the importance of flexible configuration for diverse use cases. ## ๐Ÿ”„ Refactor Appendix โ€” How I Built It: Related Posts Block ### ๐Ÿ“š Literature Atoms (H3) #### Related posts functionality deliberately excluded from WordPress core > [!quote] ID:rw_001 > Nor should it be in WordPress core. It's something that is pretty clearly in plugin territory, in my opinion. **Context & use**: - Author's rationale for building custom solution - Illustrates WordPress philosophy of core minimalism vs plugin ecosystem **Tags**: #xref <!-- atomicity: 1 idea โœ“ --> #### Studying core block patterns provides implementation foundation > [!quote] ID:rw_002 > I basically took what the post template block is doing and put it into the edit.js file for the Related Posts block. **Context & use**: - Practical development approach for custom blocks - Demonstrates value of understanding existing Gutenberg patterns **Tags**: #xref <!-- atomicity: 1 idea โœ“ --> #### Custom taxonomy mapping enables related content across post types > [!quote] ID:rw_003 > I ended up adding in settings to the plugin's settings screen where a user could choose what taxonomy would be used for the block for each post type. **Context & use**: - Solution for multi-post-type support in related content features - Shows importance of configuration flexibility in block development **Tags**: #articleseed <!-- atomicity: 1 idea โœ“ --> ### ๐Ÿง  Permanent Candidates (H4) #### WordPress core deliberately maintains minimal scope **Claim**: WordPress core intentionally excludes common features like related posts to maintain simplicity and encourage plugin ecosystem growth. **Evidence pointer**: [[#Related posts functionality deliberately excluded from WordPress core]] **Scope & conditions**: Applies to features that are useful but not essential for basic content management **Links**: - [[WordPress plugin ecosystem]] โ€” because evidence-for - [[Core minimalism philosophy]] โ€” because extends <!-- atomicity: 1 idea โœ“ --> ### โœ๏ธ Fleeting Queue - Research WordPress core inclusion criteria and decision-making process #fleeting #inbox - Investigate performance impact of related posts queries on large sites #fleeting #inbox ### โ†’ Things 3 - [ ] Test Crosswinds Blocks plugin for block development learning #things - [ ] Document React patterns from Gutenberg core for future reference #things <!-- deep-read:sections end --> ๐Ÿ“„ **Full text:** ![[Full Document Contents/Articles/How I Built It Related Posts Block.md|How I Built It: Related Posts Block by Jacob Martella]] ## Highlights - Nor should it be in WordPress core. Itโ€™s something that is pretty clearly in plugin territory, in my opinion. ([View Highlight](https://read.readwise.io/read/01ksqd5d2jhpdnx6mh4mm02tjy)) - Note: Mike Schinkel on the core/plugin boundary: related-posts is "pretty clearly in plugin territory" โ€” the core/plugin scope debate in one sentence. - Tags: core-vs-plugins, atom/literature/h2, wordpress-blocks