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:

    $current_cat    =   get_query_var('cat');
    $categories     =  
    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 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.