• so basically, i use this string on my website to get the most recent articles. <?php wp_get_archives('type=postbypost&limit=8&format=html'); ?> But as some of the title are longer than others, they sometimes spread over two lines which isn’t intended. so basically i am wondering how i would go about limiting how many characters are shown and produce a similar result to the example below.

    Original Title:
    Hello this is a really long title for an article

    limiting the characters:
    Hello this is a really long…

    i have looked at find a solution to this but there doesn’t seem to be on, or at least i cant find one…

    thanks for your help

Viewing 5 replies - 1 through 5 (of 5 total)
  • Try something like:

    p {
        text-overflow: ellipsis; /* will make [...] at the end */
        width: 370px; /* change to your preferences */
        white-space: nowrap; /* paragraph to one line */
        overflow:hidden; /* older browsers */
        }

    The ‘p’ will be your custom div class and is included in your stylesheet:

    Source

    Thread Starter person4659

    (@person4659)

    well ive just tried that placing the original code inside a paragraph and it did nothing. Im thinking maybe because it uses the wp_get_archives function and where ever that is called must put the content into a
    <li>
    really im looking to modify the actual function in some way, but 1 im not entirely sure where it is..i think i found it in wp-includes/general-template.php but then the function was huge so had no idea where to put any piece of code which would limit the amount of characters displayed

    i think i found it in wp-includes/general-template.php

    and

    change to your preferences

    Editing core WordPress files is strongly discouraged, please review how to edit CSS prior to attempting above.

    Also note that the instructions given noted this was a CSS mod (& not code to include in a paragraph).

    Thread Starter person4659

    (@person4659)

    im fully capable of editing css lol i am a web designer! and yer i tried adding the css to its div first but then tried a p tag once it wouldn’t work…

    Let me clarify:

    The 'p' will be your custom div class and is included in your stylesheet:

    Create the div and the id … so in HTML we have:

    <p id="my_id">div_content_here</p>

    and in CSS:

    #my_id {
        text-overflow: ellipsis;
        width: 370px;
        white-space: nowrap;
        overflow:hidden;
        }

    comments removed from above but still apply.

    Working Example

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Truncate wp_get_archives’ is closed to new replies.