• Resolved skitarg

    (@skitarg)


    Hi!

    First of all, i’m new at this and i’m certainly not good at programming, so please be thorough and bare with me..

    I need to shorten the title to a certain amount of characters. Also, I would like to know exactly where to put the code snippet.

    The problem I have is that the title, when it goes over two rows, destroys my design. I’ve tried all the html & css solutions I’ve come to think of. Think I need a function to take care of the problem.

    What I’ve got is:

    <h1>” rel=”bookmark” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></h1>

    Pretty basic…
    All help would be very appreciated.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Site url?

    Thread Starter skitarg

    (@skitarg)

    https://www.paratumredovisning.se/

    &

    https://www.paratumredovisning.se/bloggen

    I want the top “L?s mer” (Read more) to be aligned with one another. Have tried to put them in a separate div underneath, but can’t without affecting the loop in some way. my solution is to limit the amount of characters in the title…, so that it only can be like… 25 or so, and stay short of two rows.

    You could try adding white-space:nowrap; and overflow:hidden; to:

    .ht_box h1 {
    -x-system-font:none;
    color:#222222;
    font-family:Arial,Helvetica,sans-serif;
    font-size:26px;
    font-size-adjust:none;
    font-stretch:normal;
    font-style:normal;
    font-variant:normal;
    font-weight:200;
    line-height:normal;
    margin:0;
    padding:10px 0 0;
    text-align:left;
    }
    Thread Starter skitarg

    (@skitarg)

    that’s of course one plan. But I think I’d like a “…” after the allowed amount of characters. Like creating a php-function of sorts.

    checked the “strlen” & “substr” functions. could you help me creating a simple function using these??

    It would be greatly appreciated.

    Try something like:

    <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php substr(the_title(), 0, 12); ?>&hellip;</a></h1>

    Amend the last value in substr(the_title(), 0, 12) as needed to shorten of lengthen the no of characters displayed.

    Thread Starter skitarg

    (@skitarg)

    Thanks for all your help esmi. Your example here was a part solution and got me on the right track. Didn’t work out completely for me, but this did:

    <h2 class=”post_title”>“rel=”bookmark”><?php $s = substr(the_title(”,”,FALSE),0,30); ?>
    <?php echo $s; if (strlen($s) >29){ echo ‘…’; } ?>
    </h2>

    once again, cheers!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘the_title LENGTH’ is closed to new replies.