ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

keeping urls under control

July 03, 2007 9:38am

Subscribe [3]
  • #1 / Jul 03, 2007 9:38am

    Liam Crean

    121 posts

    How can I avoid this? (link titled ‘business link’)

    weblog looks like this:

    {exp:weblog:entries weblog="links" orderby="date" limit="50"}
    <h2 class="low">{title} </h2
    {link_address}
    {link_summary}
    {link_image}
    {/exp:weblog:entries}

    Is there a character limit property or some such device for reigning longer than usual words like links for example.

    Cheers, Liam

  • #2 / Jul 03, 2007 10:10am

    Derek Jones

    7561 posts

    You can use CSS to keep it from spilling out of its content area with overflow: hidden; / overflow: auto;.  To physically limit the characters will depend largely on how you are entering the links in your weblog.  Are you entering a fully marked up link, or just the address, and letting the addresses be auto-converted to links?

  • #3 / Jul 03, 2007 10:34am

    Liam Crean

    121 posts

    Thanks Derek

    Don’t really want to use CSS… Users will enter an address - link is auto converted

    I found this plug-in: http://expressionengine.com/downloads/details/character_limiter/
    But can’t get it working…

    {exp:weblog:entries weblog="links" orderby="date" limit="50"}
    <h2 class="low">{title} </h2
    {exp:char_limit total="35"}{link_address}{/exp:char_limit}
    {link_summary}
    {link_image}
    {/exp:weblog:entries}

    Am I missing something easy?

  • #4 / Jul 03, 2007 10:50am

    Derek Jones

    7561 posts

    The character limiter plugin, which comes with EE by default, is also “word smart”, meaning that it does not limit a string to an exact length, but will add one word at a time until the limit is exceeded.  Since a URL has no spaces, it is all one “word”.  Also, if your link is auto-converted, then you’re passing a fully marked up link to the plugin, not just the address, so a simple “true” character limiter will not work either.

    <a href="http://example.com/">http://example.com/</a>

    Forcing this to 35 characters would yield a broken link:

    <a href="http://example.com/">http://
    __I’m afraid the solution is a bit more complex.  Option one is easier to implement, but would require that your set the {link_address} field’s formatting to “None”, and that you disable the auto-conversion of links for this weblog.  Then you could turn PHP on Output in the template (or create a simple plugin) and do the following:__
    <a href="{link_address}"><?php if (strlen('{link_address}') > 35): echo substr('{link_address}', 0, 35).'…'; else echo '{link_address}'; ?></a>

    The second option would be to create an extension that would automatically rewrite auto-created links in a truncated fashion as necessary.

  • #5 / Jul 03, 2007 10:56am

    Liam Crean

    121 posts

    Thanks derek

    I’ll take a look at your suggestions.

    Cheers, Liam

  • #6 / Jul 03, 2007 11:35am

    silenz

    1651 posts

    TruncHTML with exact=“yes” would result in what you excpected character limiter to do.

    {exp:weblog:entries weblog="links" orderby="date" limit="50"}
    <h2 class="low">{title} </h2
    {exp:trunchtml chars="35" ending="…" exact="yes"}{link_address}{/exp:trunchtml}
    {link_summary}
    {link_image}
    {/exp:weblog:entries}
  • #7 / Jul 03, 2007 11:41am

    Derek Jones

    7561 posts

    Nifty, silenz.  Have you considered submitting it to the Add-On library?

  • #8 / Jul 05, 2007 8:50am

    Liam Crean

    121 posts

    Thanks Silenz - looks good that.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases