w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
wordpress. character limit on category title using substr

You can check the string length first to see that the string is larger than 10 characters:

<?php
    $current_cat    =   get_query_var('cat');
    $categories     =  
get_categories('orderby=id&order=desc&number=16');
    foreach($categories as $category) { ?>
            <div class="latest">
            <?php the_post_thumbnail(array( 160,100 ), array( 'class'
=> 'primary' )); ?>
                <img src="domain.com/images/<?php echo
$category->category_nicename; ?>.jpg" />
            </div>
            <div class="latest-details"><a href="<?php echo
get_category_link($category->term_id); ?>"><?php echo
substr($category->cat_name, 0, 10); echo (strlen($category->cat_name)
> 10)? "...":""; ?></a>
 <?php } ?>

Here is the manual for strlen(): http://php.net/manual/en/function.strlen.php





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.