WordPress.org

Ready to get started?Download WordPress

Forums

Creating Two Columns is Stripping Tags (3 posts)

  1. rwilliams1961
    Member
    Posted 1 year ago #

    I hired a coder (now MIA) to create a function that breaks a page's content into two columns. The code works. But in the process, it strips away all the <p> tags. The code is below. Any ideas?

    function split_content() {
    global $more;
    $more = true;
    $content = preg_split('/<span id="more-\d+"><\/span>/i', get_the_content('more'));
    for($c = 0, $csize = count($content); $c < $csize; $c++) {
    $content[$c] = apply_filters('the_content', $content[$c]);
    }
    return $content;
    }  
    
    function content_split($text, $separator = ' ', $start = false ) {
    
    if ( $start === false) {
    $start = strlen($text) / 2;
    }
    
    $lastSpace = false;
    $split = substr($text, 0, $start -2);
    
    // if the text is split at a good breaking point already.
    if (in_array(substr($text, $start -2, 1), array(' ', '.', '!', '?'))) {
    
    $split .= substr($text, $start, 1);
    // Calculate when we should start the split
    $trueStart = strlen($split);
    
    // find a good point to break the text.
    } else {
    
    $split = substr($split, 0, $start - strlen($separator));
    $lastSpace = strrpos($split, ' ');
    
    if ($lastSpace !== false) {
    $split = substr($split, 0, $lastSpace);
    }
    
    if (in_array(substr($split, -1, 1), array(','))) {
    $split = substr($split, 0, -1);
    }
    
    // Calculate when we should start the split
    $trueStart = strlen($split);
    }
    //now we know when to split the text
    return substr_replace($text, $separator, $trueStart, 0);
    
    }

    [please remember to mark any posted code - see http://codex.wordpress.org/Forum_Welcome#Posting_Code ]

  2. rwilliams1961
    Member
    Posted 1 year ago #

    This is the HTML from page.php:

    <div class="first-column">
    <?php $text = get_the_content(); ?>
    <?php $separator = '</div><div class="second-column">'; ?>
    <?php echo content_split($text,$separator); ?>
    </div>
  3. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    try to apply the 'the_content' filter to the result;

    example:

    <?php echo apply_filters('the_content',content_split($text,$separator)); ?>

    http://codex.wordpress.org/Function_Reference/apply_filters

Topic Closed

This topic has been closed to new replies.

About this Topic