Support » Themes and Templates » how would i restrict the character limit i na category name

  • Resolved gbaka

    (@gbaka)


    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?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter gbaka

    (@gbaka)

    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) . '...';
    Thread Starter gbaka

    (@gbaka)

    hmmm it seems to be doing that for all titles now regardless of characters length…

    Thread Starter gbaka

    (@gbaka)

    is there a way to use a if else statement for that tag?

    Thread Starter gbaka

    (@gbaka)

    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.

    I’m trying to do something similar to this here

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘how would i restrict the character limit i na category name’ is closed to new replies.