• I am trying to limit the tags my theme outputs in my portfolio.php template. I’ve gotten it to limit the tags but it does so in my single-portfolio.php file as well.

    So, on website.com/portfolio/ I want it to list:

    Item 1
    -tag 1
    -tag 2
    -tag 3
    -tag 4
    -tag 5

    But when I click into Item 1 I want it to list all tags.

    This is the partially functioning code.

    $template_name = get_post_meta( $wp_query->post->ID, '_wp_page_template', true );
    
    add_filter( "term_links-royal_portfolio_cats", 'limit_terms');
    
    function limit_terms($val) {
    	if ( $template_name = 'portfolio.php' ) {
    	    return array_splice($val, 0, 5);
    	}
    }

    Also, if alyone can help me append a … to the items where the tag output was limited, I’d be extremely grateful. That would look like:

    Item 1
    -tag 1
    -tag 2
    -tag 3
    -tag 4
    -tag 5…

Viewing 1 replies (of 1 total)
  • Thread Starter htausch

    (@htausch)

    I think I got it working. First $template_name = get_post_meta( $wp_query->post->ID, '_wp_page_template', true ); was not needed. Next, I needed an else statement. I didn’t know how to make an else statement that showed all tags (undid the filter I just added) so I just set the number to a high amount of tags to output.

    add_filter( "term_links-royal_portfolio_cats", 'limit_terms');
    
    function limit_terms($val) {
    	if ( is_page_template('portfolio.php')) {
    	    return array_splice($val, 0, 5);
    	}
    	else {
    		return array_splice($val, 0, 20);
    	}
    }

    I’m still working on how to append the … And if anyone has a better suggestion for my else statement please let me know!

Viewing 1 replies (of 1 total)
  • The topic ‘Limit tag output only in template’ is closed to new replies.