- This topic has 9 replies, 2 voices, and was last updated 1 year, 10 months ago by David.
-
AuthorPosts
-
October 21, 2022 at 1:18 am #2380823David
Hello
I’ve set up a custom post type called products.
I’ve then set up a block element using the Element Type : Content template
This works fine and products are showing up…
https://www.alfies-antiques.com/products/I added this code so the custom post type shows in 3 columns
//ADD COLUMNS TO CUSTOM POST TYPES add_filter( 'generate_blog_columns', function( $columns ) { if ( 'products' === get_post_type() && ! is_singular() ) { return true; } return $columns; } );
My first questions is, how do I get it to show 2 columns on mobile?
My second questions is, why do the products not show up on standard taxonomy category pages…
https://www.alfies-antiques.com/category/handles-hooks/Thanks
DaveOctober 21, 2022 at 8:39 am #2381365DavidStaffCustomer SupportHi there,
1. you can use this CSS to force the CPT columns to 2 on mobile:
@media (max-width: 768px) { .archive .generate-columns { width: 50% !important; } .archive .generate-columns { padding-left: 20px !important; } }
2. Category archives will only display the
post
post-type by default.
Use thepre_get_posts
hook to add others:function db_multi_post_type_categories($query) { if($query->is_main_query() && is_category()){ $query->set('post_type', ['post', 'your-post-type']); return; } } add_action('pre_get_posts', 'db_multi_post_type_categories');
October 21, 2022 at 8:50 am #2381382DavidThanks David – how do I show 2 columns on the post category archive page?
October 21, 2022 at 9:38 am #2381445DavidStaffCustomer SupportI edited the CSS above to apply to all archives.
October 23, 2022 at 11:01 am #2383274DavidThanks David
October 24, 2022 at 3:04 am #2383883DavidStaffCustomer SupportYou’re welcome
October 31, 2022 at 7:11 am #2395200DavidHi David
So I’ve updated my custom post type archive layout, by setting up a new Element Block and using the new Element Type > Loop template, which is great by the way.
Is it possible for it to use the loop template for taxonomy category pages though? So for example this category only has one product assigned to it, but it’s showing all custom post type products…
Is it possible to set up a new loop template, that shows products per category? I don’t want to be setting it up loops for each individual category though.
https://www.alfies-antiques.com/category/desks/
Thanks
DaveOctober 31, 2022 at 8:18 am #2395612DavidStaffCustomer SupportSo for the Loop Element – its designed to use the
Inherit Query from Template
option in the Query Loop Block.
Then if you set your Display Rules to eg. Category Archive, it will pull in just the posts that match that terms of the archive page the user is viewing.October 31, 2022 at 9:10 am #2395699DavidThanks David, that’s great – loving the new loop template
November 1, 2022 at 1:08 am #2396318DavidStaffCustomer SupportAwesome – glad to hear that!
-
AuthorPosts
- You must be logged in to reply to this topic.