- This topic has 7 replies, 3 voices, and was last updated 4 years, 6 months ago by Tom.
-
AuthorPosts
-
October 15, 2019 at 6:46 am #1035132Simon
Hi Generate Press Team,
Big fan of your theme. I have a problem that I hope you can help with.
I have a site that is using a Custom Post Type (boats).
I am trying to get the Custom Post Type to appear in columns on the archive page for that post type, in the same way that the ‘normal’ post types do.
I have ‘normal’ posts set to columns-2 and that works fine. But the custom post type (boats) still shows as one column.
I have found the filter that you supply to fix this, but I can’t get it to work. I am using the Code Snippets plugin as you recommend.
I am using the following snippet of PHP to get the custom post type (boats) to ‘show’ on the website. This worked fine.
==========
function namespace_add_custom_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars[‘suppress_filters’] ) ) {
$query->set( ‘post_type’, array(
‘post’, ‘nav_menu_item’, ‘boats’
));
return $query;
}
}
add_filter( ‘pre_get_posts’, ‘namespace_add_custom_types’ );===========
I have also added the following filter from the Generate Press website. With a few changes so that it refers to my custom post type. But it doesn’t generate columns.
===========
add_filter( ‘generate_blog_columns’,’sf_boats_columns’ );
function sf_boats_columns( $columns ) {
if ( is_post_type_archive( ‘boats’ ) ) {
return true;
}return $columns;
}===========
I have de-activated all plugins and tried switching theme, still doesn’t work.
The site is being developed locally so I cannot share a url.
Thank you for any help with this.
PS. Just had a thought. The archive pages I am trying to get to display in Columns are all actually Category archives within a Custom Post Type. Rather than just the archive of the parent Custom Post Type.
eg: Custom Post Type = ‘boats’. Categories within ‘boats’ = ‘bluewater-cruiser’, ‘centreboard’ etc.
It is the category archive page that I am trying to target with the make columns filter. So I need ‘bluewater-cruiser’ archive to be in columns. I hope that is clear. Thanks again for any help.October 15, 2019 at 10:28 am #1035494TomLead DeveloperLead DeveloperHi there,
Your code looks good:
add_filter( 'generate_blog_columns', function( $columns ) { if ( is_post_type_archive( 'boats' ) ) { return true; } return $columns; } );
I would need to actually see the site in order to figure out what’s going on. Any chance you can put it up on a temp live server quickly?
October 15, 2019 at 10:38 am #1035503SimonThank you for your swift reply Tom. I will see if I can ‘make it live’ briefly and get back to you.
October 15, 2019 at 12:28 pm #1035603SimonHi Tom, I have put the site up on a subdomain. How do I supply you with url, username and password? Thank you again for this. GeneratePress rocks!
October 15, 2019 at 2:55 pm #1035684DavidStaffCustomer SupportHi there,
you can send the URL and login info via the Account Issue form:
https://generatepress.com/contact/
Please add the URL for this topic to the form so we can track.
October 17, 2019 at 10:02 am #1037415TomLead DeveloperLead DeveloperIt seems you need to target categories and tags, instead of a cpt archive.
Let’s try this:
add_filter( 'generate_blog_columns', function( $columns ) { $targets = array( 'bluewater-cruiser', 'centreboard', ); if ( is_archive( $targets ) ) { return true; } return $columns; } );
You just need to add more items to the
$targets
array.Let me know if you need more info 🙂
October 18, 2019 at 2:22 am #1037897SimonThank you Tom.
Works perfectly.
You have made my day.October 18, 2019 at 9:52 am #1038330TomLead DeveloperLead DeveloperGlad I could help! 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.