WordPress.org

Ready to get started?Download WordPress

Forums

Limit for title length (9 posts)

  1. Dbo
    Member
    Posted 4 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
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    Try editing style.css and changing:

    #footer #footerbar #footerbar-center {
    float:left;
    padding:0 14px 0 11px;
    width:273px;
    }

    to

    #footer #footerbar #footerbar-center {
    float:left;
    overflow:hidden;
    padding:0 14px 0 11px;
    width:273px;
    }

    Then add:

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

    to the bottom of style.css.

  3. Dbo
    Member
    Posted 4 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
    Theme Diva & Forum Moderator
    Posted 4 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
    Member
    Posted 4 years ago #

    Here's how to do it:

    <?php
    $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
    Member
    Posted 4 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>
    ";   						}					?> 
    
    			</div>
  7. Dbo
    Member
    Posted 4 years ago #

    bump for some clarification... :/

  8. jbbrwcky
    Member
    Posted 4 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
    Member
    Posted 4 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;

    http://img10.imageshack.us/img10/4745/rctt.png

    & here's a picture of it before;

    http://img11.imageshack.us/img11/7917/sidebarpic.png

    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