Archived topic
Number of columns in Category page
9 replies · Started by Antonio on August 26, 2021
Hello
I want to set the posts of a single category menu (https://www.poesiapresente.it/argomenti/corsi-e-lab-2021/) on three columns, please how to?
Thanks
Hi there,
you can use the generate_blog_get_column_count filter:
https://docs.generatepress.com/article/using-columns-in-the-blog/#changing-the-number-of-columns
your code would be something like;
add_filter( 'generate_blog_get_column_count','tu_search_column_count' );
function tu_search_column_count( $count ) {
if ( is_category('the_category_term_slug') ) {
return 33;
}
return $count;
}
Just amend the the_category_term-slug to match.
This article explains adding PHP.
Hi, thanks for reply.
Using Code Snippets plugin I created a new snippet and inserted this:
add_filter( 'generate_blog_get_column_count','tu_search_column_count' );
function tu_search_column_count( $count ) {
if ( is_category('corsi-e-lab-2021') ) {
return 33;
}
return $count;
}
where corsi-e-lab-2021 is the category slug but it is still on one column.
Can you also add this as well?
add_filter( 'generate_blog_columns','tu_portfolio_columns' );
function tu_portfolio_columns( $columns ) {
if ( is_category('corsi-e-lab-2021') ) {
return true;
}
return $columns;
}
Perfect, thanks a lot.
No problem :)
Sorry, if I try to do the same for another category (https://www.poesiapresente.it/argomenti/corsi-e-lab-conclusi/) cloning the two snippets and changing the slug, I get this warning:
The snippet has been deactivated due to an error on line 3:
Cannot redeclare function tu_portfolio_columns.
for this snippet:
add_filter( 'generate_blog_columns','tu_portfolio_columns' );
function tu_portfolio_columns( $columns ) {
if ( is_category('corsi-e-lab-conclusi') ) {
return true;
}
return $columns;
}
the other one is ok.
Hi Antonio,
You don't have to add in a new snippet.
You only need to change the if() condition of the existing one.
Example, if you want to include more categories, change line if ( is_category('corsi-e-lab-2021') ) to:
if ( is_category(array('corsi-e-lab-2021','corsi-e-lab-conclusi')) )
And if you want to add more, just include it inside the array()
example:
if ( is_category(array('corsi-e-lab-2021','corsi-e-lab-conclusi','another-category-slug','one-more-category-slug')) )
Thanks a lot.
No problem. :D