- This topic has 8 replies, 4 voices, and was last updated 2 years, 7 months ago by Annamari.
-
AuthorPosts
-
February 5, 2021 at 2:36 pm #1647535Simon
Hey Guys,
I have a question about custom post types and the default archive page. Let me try to explain:1. I created a custom post type “news”, essentially a copy of the default posts.
2. I use this function, to display the custom post type on the default archive here:add_action('pre_get_posts', 'query_post_type'); function query_post_type($query) { if($query->is_main_query() && ( is_category() || is_tag() )) { $query->set( 'post_type', array('post','news') ); } }
As you can see, there are custom post types (the 2 on the top) and “normal” WordPress posts displayed on the archive page.
How can I add the CSS classes for the column layout & masonry the custom posts displayed on this page? (It seems like the Generatepress CSS classes are missing on the custom post type divs and images)
I already checked out your help page on this, but it seems not to work for my case πThank you so much in advance, I really love this theme and appreciate the work you put in it!
Best Regards,
SimonFebruary 5, 2021 at 3:11 pm #1647554YingStaffCustomer SupportHi Simon,
The news category archive page is actually having the masonry. It’s not obvious right now because the contents are happen to be the almost the same in height.
As you can see, if I add some more content in the title of the first post, the masonry layout would show.
https://www.screencast.com/t/japM8DYtLet me know π
February 5, 2021 at 3:39 pm #1647567SimonHey Ying,
this was just the server-side cache.Feel free to reload the page, and you should be able to see it.
Thank you by the way, you are really fast!
February 5, 2021 at 4:44 pm #1647607YingStaffCustomer SupportFebruary 6, 2021 at 4:05 am #1647894SimonThanks again Ying,
unfortunately, I already tried that.The Code now looks like this:
add_action('pre_get_posts', 'query_post_type'); function query_post_type($query) { if($query->is_main_query() && ( is_category() || is_tag() )) { $query->set( 'post_type', array('post','news') ); } } add_filter( 'generate_blog_columns','tu_news_columns' ); function tu_news_columns( $columns ) { if ( is_post_type_archive( 'news' ) ) { return true; } return $columns; }
But the site still looks the same, and the CSS classes are not applied. I guess the problem is, that this is the default archive page… But I don’t know how to fix it π
February 6, 2021 at 10:31 am #1648415TomLead DeveloperLead DeveloperHi there,
Try this instead:
add_filter( 'generate_blog_columns', function( $columns ) { if ( 'news' === get_post_type() && ! is_singular() ) { return true; } return $columns; } );
February 6, 2021 at 10:37 am #1648420SimonHey Tom,
thank you, worked instantly πHave a great day, stay safe and best regards from Germany π
SimonFebruary 7, 2021 at 11:33 am #1649443TomLead DeveloperLead DeveloperGlad I could help. Thanks, you too! π
September 25, 2021 at 1:55 pm #1942857AnnamariTom’s code worked for me too, thank you. (Been browsing the forum for 2 days to find a solution that works, maybe you should add this to the page Ying linked above.)
-
AuthorPosts
- You must be logged in to reply to this topic.