how would i restrict the character name in a category name and put "..." at the end i know how to do this with post names but have no idea how to do it with a category name, anyone?
how would i restrict the character name in a category name and put "..." at the end i know how to do this with post names but have no idea how to do it with a category name, anyone?
Use the PHP substr function.
I know how to use that for post title but not sure how to do it for category...
the best i have so far is
<?php
foreach((get_the_category()) as $category) {
echo ShortenText($category->cat_name);
} ?>
shortentext being a code i have in the function, it works except every time theres a space in the name that cuts off it cuts off the whole word instead of the number of characters. this is the example of what happens
if i want for it to cut off on 7 characters
"category" it would change it to "categor..."
but if it's this
"new category" instead of this "new cat..." it does this "new ..."
Change:
echo ShortenText($category->cat_name);
to
echo substr($category->cat_name, 0, 7) . '...';hmmm it seems to be doing that for all titles now regardless of characters length...
is there a way to use a if else statement for that tag?
Don't know why not...see http://php.net/manual/en/control-structures.if.php
oh i figured it out using the function.php thanks for the help
My original code worked i just realized that one part of it was just interfering with the spacings.
You must log in to post.