Limit for title length (9 posts)

  1. Dbo
    Posted 6 years ago #

    I am looking for a way/code to limit the title length in the recent comments section of my website (www.triplecz.com)

    For example, with very long titles such as ''2010 LAMBORGHINI GALLARDO LP550-2 VB''

    I do not want it to say User @ ''2010 LAMBORGHINI GALLARDO LP550-2 VB'' because that is too long and it creates two lines for one entry and with a total of 4 entries it moves the copyright under it everytime and it could get annoying for users.

    I would just want to be able to set a limit for it at a maximum of certain amount of words or characters, can this be done ?

  2. esmi
    Forum Moderator
    Posted 6 years ago #

    Try editing style.css and changing:

    #footer #footerbar #footerbar-center {
    padding:0 14px 0 11px;


    #footer #footerbar #footerbar-center {
    padding:0 14px 0 11px;

    Then add:

    #footer #footerbar #footerbar-center li a {white-space:nowrap;}

    to the bottom of style.css.

  3. Dbo
    Posted 6 years ago #

    Hey esmi, thank you for the reply. I tried out what you said and it's almost what I want. I should've explained just a bit better. Before it would do the following;

    User @ ''2010 LAMBORGHINI GALLARDO LP550-2 VB''

    With what you suggested, it just cuts out as soon as it reaches the line which does avoid the fact that it double lines.

    Here is what I want it to do;

    User @ ''2010 LAMBORGHINI GALLAR...''

    Like it would input the three dots after a certain amount of characters and then would close with the '', is this possible ?

    Thanks again!

  4. esmi
    Forum Moderator
    Posted 6 years ago #

    Not possible with CSS I'm afraid (which was the easy, quick, fix). You'd need to delve into the code to create the effect you want. Are you using the Recent Comments widget from Admin/Appearance/Widgets? Or does the theme create the Recent Comments itself?

  5. jbbrwcky
    Posted 6 years ago #

    Here's how to do it:

    $tit = the_title('','',FALSE);
    echo substr($tit, 0, 55);
    if (strlen($tit) > 55) echo " ...";

    You'd have to edit the comments section a little, but you can definately set how long the comment title will be with this.

  6. Dbo
    Posted 6 years ago #

    @ esmi; the theme creates it.

    @jb; thank you for the code but I have two questions. For one, will the code you gave me apply to comments that people will make in my articles ? For two, exactly where do I put this in the comments php ? :/

    Just in case, here's the code that creates the recent comments;

    <div id="footerbar-center">
    				<h3>Recent Comments</h3>
    				<ul class="footerbar-center-in">
    <?php						$sql = "SELECT * FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' ORDER BY comment_date DESC LIMIT 0 , 4";						$comments = $wpdb->get_results($sql);						foreach ($comments as $comment) {							$data = $comment->comment_author . " @ [" . $comment->post_title;							echo "
    <li><a>comment_post_ID) . "\">" . substr($data,0,40) . "]</a></li>
    ";   						}					?> 
  7. Dbo
    Posted 6 years ago #

    bump for some clarification... :/

  8. jbbrwcky
    Posted 6 years ago #

    foreach ($comments as $comment) {
      $title = $comment->comment_author . " @ [" . $comment->post_title;
      echo "<a href=\'your link here\'>";
      echo substr($title, 0, 40);
      echo "</a>]";

    That should work - have you tried it?

  9. Dbo
    Posted 5 years ago #

    Im sorry, I was away for a couple of days and wasnt able to do it in that time but yes indeed I just tried it today and its not working out too well :/

    For one it isn't giving the appropriate link to each article, it's just giving an ending as follows; \'your

    It also isn't ordered with bullets anymore, along with the font being different too, everything is underlined now too and there is no [...] when the title exceeds the number of characters.

    Here's a picture of it now with the change you suggested;


    & here's a picture of it before;


    Any ideas on how to fix or there's no real way to do this ?

Topic Closed

This topic has been closed to new replies.

About this Topic