Site logo

Archived topic

How to make custom post type look like the blog listing?

7 replies · Started by Laurentiu on December 25, 2022

Viewing posts 1–8 of 8

I have this page built using a custom post type and I want the items in the page to look like the listing of the blog (3-4 articles on a row).
I have copied the archive.php into archive-airfields.php

Thank you very much, Fernando.
One last question - how can I add a default image if there is no one for a custom post type? Same page.

What default image are you referring to? Can you provide an example?

The site seems down at the moment as well.

It's up now. So in this page I have 2 dummy airfields. One has a featured image, the other one doesn't. I would like to have all airfields to have a default image, if they don't have a featured one.

You can give the Image Block a class add-fallback-image.

Adding Custom Classes: https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/

Then, add this snippet:

add_filter('generateblocks_dynamic_image_fallback', function($url, $attributes, $block){
	if ( !is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'add-fallback-image' ) !== false ) {
		if ( ! $url ) {
		return 'https://fazarcon.pluginsupportwp.com/wp-content/uploads/2022/07/3e9923c1-0c5b-3596-89ba-ab44f6056643.jpg';
		}
	}
	
	return $content;
}, 10, 3);

Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

Replace the image URL in the code with your Image URL.

Thank you. It works great.

You're welcome, Laurentiu!

This archived topic is closed to new replies.