Archived topic
How to make custom post type look like the blog listing?
7 replies · Started by Laurentiu on December 25, 2022
Hi Laurentiu,
You'll first need to apply columns to your CPT. See this article: https://docs.generatepress.com/article/using-columns-in-the-blog/#adding-columns-to-your-custom-post-type
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
Then, you can use a Block Element - Content Template to style it as you prefer: https://docs.generatepress.com/article/block-element-content-template/
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!
