Web Analytics Made Easy -
StatCounter Limiting Char in title (wordpress widget) - CodingForum

Announcement

Collapse
No announcement yet.

Limiting Char in title (wordpress widget)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resolved 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; Aug 25, 2011, 03:28 PM.

  • #2
    You could substr() to select only a certain portion of the title string.
    Last edited by kunz; Aug 26, 2011, 04:29 AM.
    “Don't pray for lighter burdens, but for stronger backs.”
    Deals in Sydney

    Comment


    • #3
      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; Aug 24, 2011, 04:32 PM.

      Comment


      • #4
        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.
        PHP Code:
        header('HTTP/1.1 420 Enhance Your Calm'); 
        Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

        Comment


        • #5
          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.

          Comment

          Working...
          X
          😀
          🥰
          🤢
          😎
          😡
          👍
          👎