• Hi all!
    I have expirenced some problems while using the “more tag” feature of wordpress 2.5. Specifically, it happens that when I want to use the “more” feature to divide this text:

    <div>
    some text
    
    other text
    </div>

    wordpress produces this output

    <div>
    some text

    which obviously breaks my layout.
    A quirk trick to workaround this problem is this:

    Add this function somewhere in your function.php file (usually located in your own style’s directory, under wp-content/themes/YOURLOOK/functions.php)

    function close_dangling_tags($html){
      #put all opened tags into an array
      preg_match_all("#<([a-z]+)( .*)?(?!/)>#iU",$html,$result);
      $openedtags=$result[1];
      asort($openedtags);
    
      #put all closed tags into an array
      preg_match_all("#</([a-z]+)>#iU",$html,$result);
      $closedtags=$result[1];
      asort($closedtags);  
    
      $len_opened = count($openedtags);
      for($i=0;$i < $len_opened;$i++) {
        if ($openedtags[$i]!="" && !in_array($openedtags[$i],$closedtags)){
          $html .= '</'.$openedtags[$i].'>';
        }
      }
    
      $len_closed = count($closedtags);
      for($i=0;$i < $len_opened;$i++) {
        if ($closedtags[$i]!="" && !in_array($closedtags[$i],$openedtags)){
          $html = '<'.$closedtags[$i].'>' . $html;
        }
      }
    
      return $html;
    }

    And add this lines, where the more tag is causing you problem. You’ll usually have to replace the <?php the_content(); ?> block with the following one, search and replace for it in the file wp-content/themes/YOURLOOK/index.php)

    old block

    <?php the_content(); ?>

    new block

    <?php
    						 ob_start();
    							the_content('(Continua...)');
    					    	$the_content_text = ob_get_contents();
    					    ob_end_clean();
    						echo close_dangling_tags($the_content_text); ?>

    It works. It would be very useful to build up a single plugin based on this hack, if you’d like to do it, then you’re welcome!

    Best regards from Italy,
    Antonio

  • The topic ‘more tag hack’ is closed to new replies.