A server-rendered posts grid for WordPress. Show your latest posts as a responsive grid or list, filter by category, and add pagination, all from the block editor.
Try it live in WordPress Playground (no install needed)
Blog and portfolio pages need content that updates itself. This is a dynamic block: the markup is generated by PHP on every request, so new posts appear automatically with no editing, and the editor shows a live preview.
- Grid (1-4 columns) or list layout, responsive on mobile
- Filter by one or more categories
- Order by newest or title
- Toggle featured image, excerpt, date and pagination
- Live preview in the editor using
ServerSideRender - Secure by default: every attribute is validated and all output is escaped
- Download this repository as a ZIP (Code → Download ZIP).
- In WordPress go to Plugins → Add New → Upload Plugin, upload the ZIP and activate it.
- Edit a page and add the Dynamic Posts Grid block.
The compiled build/ folder is included, so no build step is needed.
git clone https://github.com/YOUR-USERNAME/dynamic-posts-grid-block.git
cd dynamic-posts-grid-block
npm install
npm run buildRequires Node 18+ and WordPress 6.4+.
| Attribute | Type | Default | Description |
|---|---|---|---|
postsToShow |
number | 6 |
Posts per page (1-24) |
columns |
number | 3 |
Grid columns (1-4) |
layout |
grid / list |
grid |
Display style |
categories |
number[] | [] |
Category IDs, empty means all |
orderBy |
date / title |
date |
Sort order |
showImage / showExcerpt / showDate |
boolean | true |
Card content |
showPagination |
boolean | false |
Newer / Older links |
Editor (edit.js) ──attributes──▶ ServerSideRender ──REST──▶ render.php
│
Front end request ─────────────────────────────────────────────────▶│
▼
sanitize → WP_Query → escaped HTML
src/
├── block.json Attributes and the "render" file
├── index.js Registers the block (no save function, it is dynamic)
├── edit.js Inspector controls + live preview
├── render.php Server-side output (WP_Query)
├── style.scss Front-end styles
└── editor.scss Editor-only styles
dynamic-posts-grid-block.php Plugin bootstrap
- Numeric attributes are cast with
absint()and clamped to safe ranges. - Enumerated attributes (
layout,orderBy) are checked against allow-lists. - Output uses
esc_html(),esc_url()andesc_attr(). - The pagination query var is read-only and cast to a positive integer.
npm run lint:js
npm run lint:css
npm start # watch mode- Support custom post types
- "Load more" button using the Interactivity API
- Tag filter
MIT © Mehul Dave