Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    57
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Limiting Char in title (wordpress widget)

    I Downloaded a wordpress widget and i was wondering if it was possibleto limit the char in the title.

    Snippet from the area that gives us the title

    PHP Code:
    if ($author_has_url) echo '</a>'
                echo 
    $url;
                echo 
    $comment->post_title
    complete code
    PHP Code:
      /*
        * Called by register_sidebar_widget() function.
        * Rendering of the widget happens here.
        */
       
    function widget($args) {     
          global 
    $wpdb;
          
          
    extract($args);
                
          
    $options get_option($this->_folder);
          
    $this->validate_options($options);
          
          if (
    is_single() && $options['show_in_post'] != 'checked') return;
          if (
    is_page() && $options['show_in_page'] != 'checked') return;
          
          
    $author_emails = array();
          if (!empty(
    $options['author_emails'])) {
             
    $author_emails explode(','$options['author_emails']);
          }
                
          
    $sql "SELECT a.*, b.post_title from $wpdb->comments a JOIN $wpdb->posts b ON a.comment_post_id = b.id WHERE comment_approved= '1' AND a.comment_type != 'pingback'
                  ORDER BY comment_date DESC LIMIT " 
    $options['num_of_comments'];
          
          
    $comments $wpdb->get_results($sql);
          
          echo 
    $before_widget;
          echo 
    $before_title;
          echo 
    is_single() && ($options['single_mode'] == 'checked') ? $options['single_mode_title'] : $options['title'];
          echo 
    $after_title;
          
          echo 
    '<div class="rcg-div">';
          if (
    $comments) {
             echo 
    '<ul>';
             foreach (
    $comments as $comment) {
                
    $author_has_url = !(empty($comment->comment_author_url) || 'http://' == $comment->comment_author_url);
                
    $is_author in_array($comment->comment_author_email$author_emails);
                
    $url_author '<a href="' $comment->comment_author_url '" title="' $comment->comment_author '" rel="external nofollow" target="_blank">';
                
    $url '<a href="'get_permalink($comment->comment_post_ID).'#comment-'.$comment->comment_ID .'" title="'.$comment->comment_author .' | '.get_the_title($comment->comment_post_ID).'">';
                echo 
    '<li ' . ($is_author 'class="rcg-author"' '') . '><div class="rcg-wrapper">';
                echo 
    '<div class="rcg-avatar">';
                echo 
    $author_has_url $url_author '<span title="' $comment->comment_author '">';
                echo 
    get_avatar($comment->comment_author_emailintval($options['gravatar_width']));
                echo 
    $author_has_url '</a>' '</span>';
                echo 
    '</div>';

                echo 
    '<div class="rcg-text" style="padding-left:' . (intval($options['gravatar_width']) + 10) . 'px">';
                if (
    $author_has_url) echo $url_author;
            
                if (
    $author_has_url) echo '</a>'
                echo 
    $url;
                echo 
    $comment->post_title;
                
                echo 
    '</a><br/> ';
                
                echo 
    '</div>';
                echo 
    '</div></li>';
             }
             echo 
    '</ul>';
          }
          if (
    $options['link_to_us'] == 'checked') {
             echo 
    '<div class="rcg-link"><a href="' $this->_link '" target="_blank">'__('Get this widget for your own blog free!'$this->_folder) . '</a></div>';
          }
          echo 
    '</div>';
          echo 
    $after_widget;
       } 
    Last edited by kor81; 08-25-2011 at 08:28 PM.

  • #2
    New Coder
    Join Date
    Aug 2011
    Location
    Sydney
    Posts
    26
    Thanks
    2
    Thanked 2 Times in 2 Posts
    You could substr() to select only a certain portion of the title string.
    Last edited by kunz; 08-26-2011 at 09:29 AM.
    “Don't pray for lighter burdens, but for stronger backs.”
    Deals in Sydney

  • Users who have thanked kunz for this post:

    kor81 (08-24-2011)

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    57
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Ok, i got it thank you kunz

    i replaced this
    PHP Code:
    if ($author_has_url) echo '</a>';  
                echo 
    $url
                echo 
    $comment->post_title
    with this
    PHP Code:
     if (strlen($post->post_title) > 35'</a>'
                echo 
    $url;
                echo 
    substr(the_title($before ''$after ''FALSE), 035) . '...'

    edit, nevermid that didn't work, its pulling the post title for the last post and not the title from the post last commented post
    Last edited by kor81; 08-24-2011 at 09:32 PM.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    That looks mostly right, but the variables have changed. A lot.
    Based on your first block of code, you would use:
    PHP Code:
    if ($author_has_url) echo '</a>'
                echo 
    $url;
                echo 
    strlen($comment->post_title) > 35 substr($comment->post_title035) . '...' $comment->post_title
    If that's not what you intend to do, the logic is correct you'd just need to track down which block to modify.

  • Users who have thanked Fou-Lu for this post:

    kor81 (08-25-2011)

  • #5
    New Coder
    Join Date
    Aug 2011
    Posts
    57
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    That looks mostly right, but the variables have changed. A lot.
    Based on your first block of code, you would use:
    PHP Code:
    if ($author_has_url) echo '</a>'
                echo 
    $url;
                echo 
    strlen($comment->post_title) > 35 substr($comment->post_title035) . '...' $comment->post_title
    If that's not what you intend to do, the logic is correct you'd just need to track down which block to modify.
    That worked, thank you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •