Ready to get started?Download WordPress


truncate text (4 posts)

  1. AnimaliX
    Posted 3 years ago #

    hi, i need truncate specific text in this case between "p" tags... i find this java script... but works only with firtst post :(


    function truncate() {
      var len = 100;
      var p = document.getElementById('truncateMe');
      if (p) {
        var trunc = p.innerHTML;
        if (trunc.length > len) {
          /* Truncate the content of the P, then go back to the end of the
             previous word to ensure that we don't truncate in the middle of
             a word */
          trunc = trunc.substring(0, len);
          trunc = trunc.replace(/\w+$/, '');
          /* Add an ellipses to the end and make it a link that expands
             the paragraph back to its original size */
          trunc += '<a href="#" ' +
            'onclick="this.parentNode.innerHTML=' +
            'unescape(\''+escape(p.innerHTML)+'\');return false;">' +
            '<span style="font-size: 10px;">[ more ... ]</span><\/a>';
          p.innerHTML = trunc;
    // Multiple onload function created by: Simon Willison
    // http://simon.incutio.com/archive/2004/05/26/addLoadEvent
    function addLoadEvent(func) {
      var oldonload = window.onload;
      if (typeof window.onload != 'function') {
        window.onload = func;
      } else {
        window.onload = function() {
          if (oldonload) {
    addLoadEvent(function() {
  2. AnimaliX
    Posted 3 years ago #

    pls... someone?

  3. kmessinger
    Volunteer Moderator
    Posted 3 years ago #

    What are you trying to accomplish?

    Can you use a plugin like http://wordpress.org/extend/plugins/excerpt-editor/

  4. AnimaliX
    Posted 3 years ago #

    i need truncate text between tags ...

    "Excerpt Editor" is not for my situation... i using php and some complex coding in posts plus multilanguage system...

    this java code in my first post working good... but only with first post :(

    (sorry for "this" english)

Topic Closed

This topic has been closed to new replies.

About this Topic