[Support request] Stuck with some Custom Taxonomy templating

Home Forums Support [Support request] Stuck with some Custom Taxonomy templating

Home Forums Support Stuck with some Custom Taxonomy templating

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1418748
    Henry

    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!

    #1418797
    David
    Staff
    Customer Support

    Hi 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; 
    }
    #1418831
    Henry

    Thanks, David, really appreciate your help. I tried (via PHP Snippets) and I get this error:

    Parse error: syntax error, unexpected '{', expecting '(' on line 8

    #1418895
    David
    Staff
    Customer Support
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.