This code enables you to pull related posts from your database and display them in a grid within the content of your post or page using a shortcode or Gutenberg / Genesis block.
The solution uses CSS
display:grid; to print each entry in a 3 column grid.
Shows the related shortcode added between paragraphs of content on the Edit post screen display related posts.
Tested using the Genesis Sample child theme by StudioPress however will work in any Genesis child theme or any WordPress theme if you swap out the
genesis_get_image function with
There’s 2 steps :
- # Copy & paste the PHP code ( without the opening PHP tag ) from the
functions.phpfile to the end of your child themes functions file.
- # Copy & paste the CSS to the end of your child themes style sheet and clear caching.
You can then add the [related] posts shortcode within the content of your post or page like this :