WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] how would i restrict the character limit i na category name (9 posts)

  1. gbaka
    Member
    Posted 4 years ago #

    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?

  2. MichaelH
    Member
    Posted 4 years ago #

  3. gbaka
    Member
    Posted 4 years ago #

    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 ..."

  4. MichaelH
    Member
    Posted 4 years ago #

    Change:

    echo ShortenText($category->cat_name);

    to

    echo substr($category->cat_name, 0, 7) . '...';
  5. gbaka
    Member
    Posted 4 years ago #

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

  6. gbaka
    Member
    Posted 4 years ago #

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

  7. MichaelH
    Member
    Posted 4 years ago #

  8. gbaka
    Member
    Posted 4 years ago #

    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.

  9. Kevin Kwok
    Member
    Posted 4 years ago #

    I'm trying to do something similar to this here

Topic Closed

This topic has been closed to new replies.

About this Topic