• Hello, i am using the_content_limit () function on my home page and i will be applying it to archives as well. The only problem is that the function removes all text formatting from the excerpts displayed on the homepage. I DO want the images to be removed, but NOT the text formatting (bold, italic, links, etc.)

    I did a little research and i think it has to do with the strip_tags($content). But i haven’t found a clear solution to my problem, or at least not one i could understand. Here is the code from my functions.php file:

    <?php function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
        $content = get_the_content($more_link_text, $stripteaser, $more_file);
        $content = apply_filters('the_content', $content);
        $content = str_replace(']]>', ']]>', $content);
        $content = strip_tags($content);
    
       if (strlen($_GET['p']) > 0) {
          echo "<p>";
          echo $content;
          echo "&nbsp;<a href='";
          the_permalink();
          echo "'>"."Read More &rarr;</a>";
          echo "</p>";
       }
       else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
            $content = substr($content, 0, $espacio);
            $content = $content;
            echo "<p>";
            echo $content;
            echo "...";
            echo "&nbsp;<a href='";
            the_permalink();
            echo "'>".$more_link_text."</a>";
            echo "</p>";
       }
       else {
          echo "<p>";
          echo $content;
          echo "&nbsp;<a href='";
          the_permalink();
          echo "'>"."Read More &rarr;</a>";
          echo "</p>";
       }
    }
    
    ?>

    Here is the_content_limit() as used in my home.php:

    <?php $recent = new WP_Query("cat=-34&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>          
    
                        <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
                           <div class="postdate"> <?php the_time('d F Y'); ?> </div>
                        <?php if( get_post_meta($post->ID, "thumbnail", true) ): ?>
                   <a href="<?php the_permalink() ?>" rel="bookmark"><img style="float:left; margin:10px 10px 0px 5px" src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" alt="<?php the_title(); ?>" /></a>
                   <?php else: ?>
                        <?php endif; ?>
                         <?php the_content_limit(325, ""); ?><div class="link"><a href="<?php the_permalink() ?>">Lire la suite</a></div>
                        <?php endwhile; ?>

    And here is my site: Planète Média(TIC)

    Thank you!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘modifying the strip_tags to display text formatting’ is closed to new replies.