Archived topic
Custom Post Type Archive in Columns
22 replies · Started by Johan on February 2, 2021
Hello David :-)
The ideal for this site would be that "our-formations" as well as all the children categories are in columns (3 col if possible?):
- securite-incendie
- sante-et-prevention
- securite
- vtc
- hygiene
In addition, I would like to have for each card a button with the text "Discover this training"
Is it possible ?
Thank you
So you should be able to check if the category is an ancestor. So this line:
if ( is_category( 'nos-formations' ) ) {
becomes:
if ( is_category( 'nos-formations' ) || cat_is_ancestor_of( 'nos-formations' ) ) {
This gives me an error, see here: https://dev1.directsolutions.fr/offres/nos-formations/securite/
or
https://dev1.directsolutions.fr/offres/nos-formations/securite-incendie/
What's the error? Can you check your error_log file for something specific?
Let us know :)
Hello,
Nothing is displayed in debug mode (wp-config = define ('WP_DEBUG', true);), the page is blank (ex. : https://dev1.directsolutions.fr/offres/nos-formations/securite-incendie/)...
Here is what Query monitor indicates: "Fatal error: Uncaught Error: Too few arguments for the cat_is_ancestor_of () function, 1 passed in /home/directl/dev1/wp-content/themes/generatepress_child/functions.php on the line 88 and exactly 2 expected
in /home/directl/dev1/wp-includes/category.php at line 246 "
Ah, try this:
$category = get_queried_object();
if ( is_category( 'nos-formations' ) || cat_is_ancestor_of( $category->term_id, 'nos-formations' ) ) {
Hello Tom and thank you :-)
Indeed with this code I have no more errors however I have no columns either :-(
I put the current full code below for verification:
add_filter( 'generate_blog_columns','tu_formation_columns' );
function tu_formation_columns( $columns ) {
$category = get_queried_object();
if ( is_category( 'nos-formations' ) || cat_is_ancestor_of( $category->term_id, 'nos-formations' ) ) {
return true;
}
return $columns;
}
Is this code doing anything on the nos-formations category page?