- This topic has 7 replies, 2 voices, and was last updated 3 years, 4 months ago by
Fernando.
-
AuthorPosts
-
December 25, 2022 at 8:18 am #2473025
Laurentiu
December 25, 2022 at 8:51 pm #2473271Fernando Customer Support
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/
December 25, 2022 at 10:53 pm #2473320Laurentiu
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.December 25, 2022 at 11:32 pm #2473341Fernando Customer Support
What default image are you referring to? Can you provide an example?
The site seems down at the moment as well.
December 25, 2022 at 11:34 pm #2473342Laurentiu
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.
December 25, 2022 at 11:57 pm #2473354Fernando Customer Support
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.
December 26, 2022 at 1:13 am #2473411Laurentiu
Thank you. It works great.
December 26, 2022 at 1:41 am #2473434Fernando Customer Support
You’re welcome, Laurentiu!
-
AuthorPosts
- You must be logged in to reply to this topic.