Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide/Show if Count is Greater Than 5

I am working in a WordPress theme and found a problem that I am a bit confused on. I am showing a list of offices in different cities. This is a custom taxonomy and I am using the following code to display a unordered list of terms.

$wpz_offices = get_the_term_list( $post->ID, 'office', '<li>', '</li><li>', '</li>');
echo $wpz_offices;

And it display exactly how it should but the problem is I would like to add a javascript toggle if the <li> exceeds 5. I do not know enough about JavaScript to implement this so this is why I am asking for help. Is this possible using the available markup?

So basically if the <ul> for the taxonomy has 4 or less terms then show normally

  • a
  • b
  • c
  • d

But if we have 5 terms show this

To see all offices Click here

Any help would be appreciated.

Update For those curious here is how I used the help from the answers http://jsfiddle.net/KQBKu/

like image 454
Juan Rangel Avatar asked Nov 27 '25 02:11

Juan Rangel


1 Answers

Demo http://jsfiddle.net/yGt4y/

This should give you good idea. :)

API: http://api.jquery.com/slideToggle/

Code

$(document).ready(function () {

    if ($('ul > li').length > 3) {
        $('#click').show();
        $('ul').hide();
    }

    $('#click').click(function () {
        $('ul').slideToggle();
    });
});
like image 100
Tats_innit Avatar answered Nov 28 '25 14:11

Tats_innit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!