The MU forums have moved to WordPress.org

Limited number of characters (7 posts)

  1. boonika
    Member
    Posted 15 years ago #

    There is a 'Description' field inside 'Your Profile'. I'm using this code to display it on top of my sidebar:

    <div id="abouttext">
    		<ul>
    		<h2>Services:</h2> <?php
    function print_profile() {
           global $wp_query, $blogownerid;
           global $wpdb, $blog_id;
    	$blogownerid = $wpdb->get_var("SELECT post_author FROM wp_" . $blog_id . "_posts");
    $userdata = get_userdata($blogownerid);
     if ($userdata->description != '') {
    echo $userdata->description; }
    }
    echo print_profile(); ?></ul>
    </div>

    As this sidebar field has it's max height defined, I want to limit number of characters/letters inside 'Description' box to, let say - 100. Any idea on how to do this?

    Thanks

  2. MrBrian
    Member
    Posted 15 years ago #

    substr($userdata->description, 0, 100);

  3. boonika
    Member
    Posted 15 years ago #

    Thanks MrBrian, but where exactly should I paste this code. I tried few options but none of them worked. Thanks.

  4. MrBrian
    Member
    Posted 15 years ago #

    You could have googled and found out about the substr function, but whatever. In your code, replace
    echo $userdata->description;

    with

    echo substr($userdata->description, 0, 100);

  5. boonika
    Member
    Posted 15 years ago #

    Thanks MrBrian. I thought that code you provided should be placed somewhere inside user-edit.php and that's why I didn't get any results. Originally I wanted to disallow blog owners to write more than 100 characters inside 'Your Profile'/'Description' box. But this will also do the trick. Thanks.

  6. cafespain
    Member
    Posted 15 years ago #

    @boonika: How's your jQuery or javascript? You could write a plugin that loads a javascript function on the profile page which listens to the keypress of the authors box and stops accepting input after 100 characters.
    Hey you could even put a counter on the page so the user can keep track. Wonderful thing this jQuery.

  7. boonika
    Member
    Posted 15 years ago #

    Sounds interesting but for now, text explanation bellow the Derscription text-box will do the trick.

    Everything is a little bit complicated when it comes to me and programming. I'm a designer and painter and my function here is to be pain in the ass to real programmers:) Before I came to WPMU forums I didn't know s... about coding (php & css), but I've learned a lot in last year and a half, thanks to you and other nice folks here). I use other people code and modify it to suite my needs. That's my style:)

    About 'js'... like it a lot but I'm too 'freesh' to start writing functions by myself. But I did manage to modify pages drop-down menu by myself:D I like MooTools. I even wanted to create a 'js' powered categories-widget (really cool concept) plugin but as I said previously - too fresh.

About this Topic