- This topic has 12 replies, 2 voices, and was last updated 1 year, 12 months ago by David.
-
AuthorPosts
-
April 27, 2022 at 11:35 am #2202052Samuel
Hello,
Here is my situation :
– I have CPT that are Hotel reviews
– Each Hotel has several categories (price, style, etc.) that leads to archive pages.My problem is I don’t know how to modify these archive page layout.
I would need things like have posts displaying in 2 or 3 columns, add a button “read more”, etc.I’ve tried using the GP blog customizer but it’s not having any effect.
I’ve tried using Layout Element but it’s only affecting general things (and deactivating featured image is not working.)
I’ve tried using Header Element to customise it but it’s not working.
I’ve tried using the Bloc Element but don’t really figured out how to achieve what I wanted to do.It seems that neither the GP standard blog customization nor the GP Element solutions seem to have any effect on these CPT archive pages.
I surely miss something here as I’m not an expert on PHP and CPT stuffs…
Well, if you can help me on this, it will be much appreciated !
Thanks by advance,
SamuelPS : you’ll find an example of a CPT Archive page in Private information.
April 27, 2022 at 1:08 pm #2202122DavidStaffCustomer SupportHi there,
to add the GP Blog Columns to a CPT requires this PHP Snippet:
add_filter( 'generate_blog_columns', function( $columns ) { if ( 'CPT_SLUG' === get_post_type() && ! is_singular() ) { return true; } return $columns; } );
Swap the
CPT_SLUG
for your slug.How is the excerpt added to the CPT ? Are you using a custom excerpt ?
April 27, 2022 at 1:17 pm #2202129SamuelThanks David,
The excerpt is added handly into the excerpt field of the custom post.
I’ve already tried to add the snipet without success. The slug has to be entirely insert right ? like ‘mydomain.com/my-custom-archive-page’ ? Or do I miss something ?
April 27, 2022 at 1:25 pm #2202133DavidStaffCustomer SupportWhat is the name of the CPT ? The slug is just that.
The Read More has to be enabled on Custom excerpts:
https://docs.generatepress.com/article/activating-read-custom-excerpt/
April 27, 2022 at 1:49 pm #2202143SamuelOk ! I understood my mistake, it’s working now.
Button is added as well,
Thanks a lot !I have other questions if you can give me a lead :
1 / Is there a possibility to make the read more button redirecting to custom url instead of post url ? (each post has a custom url in a custom field)
2 / What would be the proper way to remove featured image and just keep the title archive page ?
3 / Is it possible to display categories name below title post name in archive page ?
April 27, 2022 at 2:19 pm #2202160DavidStaffCustomer SupportGood to hear that.
How were the CPT Templates created ? As there are a few options we can approach this.
April 27, 2022 at 2:21 pm #2202163SamuelCreated manually in my function.php file
April 27, 2022 at 2:24 pm #2202174DavidStaffCustomer SupportDid you add templates like in this doc:
https://docs.generatepress.com/article/setting-up-a-simple-custom-post-type/
April 27, 2022 at 2:24 pm #2202175SamuelBy the way, regarding redirection to custom URL, I’m using this snipet to do it with WPSP but it would be nice to be able to redirect directly from the archive pages also.
I imagine it should be something similar but pointing the read more button filter on archive pages or something like that ?
<?php add_filter( 'wpsp_title_href', function( $href ) { $custom_url = get_post_meta( get_the_ID(), 'url-booking', true ); if ( $custom_url ) { return $custom_url; } return $href; } ); add_filter( 'wpsp_image_href', function( $href ) { $custom_url = get_post_meta( get_the_ID(), 'url-booking', true ); if ( $custom_url ) { return $custom_url; } return $href; } ); add_filter( 'wpsp_read_more_output', function( $output, $settings ) { $custom_url = get_post_meta( get_the_ID(), 'url-booking', true ); if ( $custom_url ) { return sprintf( '<div class="wpsp-read-more"><a title="%1$s" class="%4$s" href="%2$s">%3$s</a></div>', the_title_attribute( 'echo=0' ), esc_url( $custom_url ), __( 'Voir les tarifs', 'wp-show-posts' ), esc_attr( $settings['read_more_class'] ) ); } return $output; }, 10, 2 ); add_filter( 'wpsp_terms_output', function( $output ) { return strip_tags( $output ); } ); ?>
April 27, 2022 at 2:31 pm #2202180SamuelDid you add templates like in this doc:
https://docs.generatepress.com/article/setting-up-a-simple-custom-post-type/
I don’t think so, I found PHP function somewhere and just added it in my function.php
April 27, 2022 at 2:43 pm #2202189DavidStaffCustomer SupportOk, so I assume it using the themes templates.
If that’s the case then you should be able to design/build your own Block Element – Content Template:https://docs.generatepress.com/article/block-element-content-template/
With its Dynamic Data options you can set a Link to use the Dynamic Data Type > Post Meta to use a Custom Field
April 27, 2022 at 3:21 pm #2202210SamuelWow ! I didn’t notice that feature but this is perfect. Thanks a lot !
It opens a lot of possibilities !
It makes you rethink a lot of work that has been done, to do it differently… and with the merge of WPSP and GB I’ll have to rethink all my custom organization as well, a lot of work ahead !April 27, 2022 at 3:34 pm #2202219DavidStaffCustomer SupportAwesome – glad to hear that’s going to work for you.
You should be aware that the GB update will introduce dynamic data options inside GB , so you will have some new features to play with 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.