- This topic has 3 replies, 2 voices, and was last updated 3 years, 8 months ago by David.
-
AuthorPosts
-
August 26, 2020 at 4:48 am #1418748Henry
This snippet works great to create a two-column layout for Custom Taxonomy.
add_filter( 'generate_blog_columns','tax_country_portfolio_columns' ); function tax_country_portfolio_columns( $columns ) { if ( is_tax( 'country' ) ) { return true; } return $columns; }
However, the issue is that I’d like to NOT have a two-column layout on some of the “country” taxonomy pages. Is there a way to do this?
Is the approach to use an ELSE statement?
I tried this but it didn’t work because I’ve misued the way WordPress and the “tax” slug work (I think).
If there’s anyone good at PHP can you please take a look and advise please?
Here’s my attempt:
add_filter( 'generate_blog_columns','cpt_archive_portfolio_columns' ); function cpt_archive_portfolio_columns( $columns ) { $cats = array('term-3','term-4','term-16','term-1','term-9'); foreach($cats as $cid) { if ( is_tax( $cid ) ) { return false; } else return true; } return $columns; }
An example of a page I am trying to prevent from having two columns has a slug, like this:
"country/united-kingdom"
And the body tag is like this:
<body class="archive tax-country term-austria term-249 wp-custom-logo wp-embed-responsive cookies-not-set post-image-above-header post-image-aligned-center generate-columns-activated wp-schema-pro-2.1.2 no-sidebar nav-float-right fluid-header separate-containers active-footer-widgets-0 header-aligned-left dropdown-hover" itemtype="https://schema.org/Blog" itemscope>
All help gratefully received – thanks!
August 26, 2020 at 5:24 am #1418797DavidStaffCustomer SupportHi there,
the is_tax() conditional tag is made up of two arguments, first is the $taxonomy, then the optional $term
https://developer.wordpress.org/reference/functions/is_tax/
Try this, it will first check if it is ‘country’ and the check if the $term exists
add_filter( 'generate_blog_columns','cpt_archive_portfolio_columns' ); function tax_country_portfolio_columns( $columns ) { // Check if country taxonomy if ( is_tax( 'country') ) { // Check terms are in array if ( is_tax( 'country', array('term-3','term-4','term-16','term-1','term-9') ) ) { return false; } else { return true; } } return $columns; }
August 26, 2020 at 5:46 am #1418831HenryThanks, David, really appreciate your help. I tried (via PHP Snippets) and I get this error:
Parse error: syntax error, unexpected '{', expecting '(' on line 8
August 26, 2020 at 6:50 am #1418895DavidStaffCustomer SupportOoops…. updated code above:
https://generatepress.com/forums/topic/stuck-with-some-custom-taxonomy-templating/#post-1418797 -
AuthorPosts
- You must be logged in to reply to this topic.