- This topic has 10 replies, 3 voices, and was last updated 1 year, 5 months ago by
David.
-
AuthorPosts
-
June 26, 2022 at 10:59 am #2265067
Hilton
Hello, I use the web-stories plugin and I’d like to know how can I customize web-story archive page so ir can display 3 columns with pagination, as this one https://bit.ly/3bua7LM . This is how my current page is looking like https://bit.ly/39R39An . Thanks
June 26, 2022 at 7:27 pm #2265275Fernando Customer Support
Hi Hilton,
You’ll need a PHP snippet to add columns to your CPT: https://docs.generatepress.com/article/using-columns-in-the-blog/#adding-columns-to-your-custom-post-type
There’s also a code here to change the number of columns.
So, yours would be:
add_filter( 'generate_blog_columns', function( $columns ) { if ( 'CPT_SLUG' === get_post_type() && ! is_singular() ) { return true; } return $columns; } );
and
add_filter( 'generate_blog_get_column_count','tu_search_column_count' ); function tu_search_column_count( $count ) { if ( 'CPT_SLUG' === get_post_type() && ! is_singular() ) { return 33; } return $count; }
Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets
Hope this helps!
June 30, 2022 at 6:09 am #2269127Hilton
Hello, I don’t know if you’ve seen the web stories archives page, which is this one https://bit.ly/39R39An . I need a specific function for that archives page, which in this case is mywebsite.com/web-stories . Your function doesn’t seem to be specific to this page.
June 30, 2022 at 6:25 am #2269150David
StaffCustomer SupportHi there,
see my reply here:
https://generatepress.com/forums/topic/web-stories-archive/#post-2197720
June 30, 2022 at 6:47 am #2269168Hilton
Hi David,
Looks like it was a great start. But first of all, this web-stories archives page is the only one on the site that will be using columns, so I believe it needs an add-on to this function. Another thing is that I would like the web-stories archive page to display only the stories, in 3 columns, and not the same format of the other archive pages, where the image, title and excerpt appear.
Thanks!
June 30, 2022 at 6:56 am #2269177David
StaffCustomer SupportThis doc explains how to set the columns:
https://docs.generatepress.com/article/using-columns-in-the-blog/#changing-the-number-of-columns
If you just want the ‘content’ to be displayed then the simplest approach would be to use a Block Element – Content Template:
https://docs.generatepress.com/article/block-element-content-template/
For your template, it sounds like you just want to add a GP Dynamic Content block to display the excerpt.
June 30, 2022 at 7:55 am #2269368Hilton
Hi David,
That is great! My page looks exactly the way I expected https://bit.ly/3AgFl3m
I added the following functions, hope it help other users:
add_filter( 'generate_blog_columns', function( $columns ) { if ( ! is_singular() && 'web-story' === get_post_type() ) { $columns = true; } return $columns; } );
add_filter( 'generate_blog_get_column_count','tu_search_column_count' ); function tu_search_column_count( $count ) { if ( ! is_singular() && 'web-story' ) { return 33; } return $count; }
add_filter( 'get_the_archive_title', function ( $title ) { if ( 'web-story' === get_post_type() ) { $title = 'Web Stories'; } return $title; },50);
June 30, 2022 at 8:10 am #2269380Hilton
David,
Just one more question, if I wanted to add the same layout to another custom post type named “video”, how can I change the function above to make it working for both (“web-stories” and “video”). Should I use an array?
Thanks
July 1, 2022 at 2:34 am #2270073David
StaffCustomer SupportAwesome – yeah you can use an array fro example:
add_filter( 'generate_blog_columns', function( $columns ) { $post_types = array( 'web-story', 'video' ); if ( ! is_singular() && in_array( get_post_type(), $post_types ) ) { $columns = true; } return $columns; } );
July 1, 2022 at 7:01 am #2270253Hilton
Thanks David! You are the best!!
July 1, 2022 at 7:14 am #2270270David
StaffCustomer SupportGlad to be of help
-
AuthorPosts
- You must be logged in to reply to this topic.