0
votes

I'm trying to create a function that allows me to SPLIT the_content in wordpress using the more <!--more--> tag in the posts field. However, I don't know what I'm doing and seem to be making a mess

In my functions.php I have the following code.

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;
}

In my homepage.php I have replaced the_content with the following function

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

        <?php
        $content = split_content();
        echo '<div>', array($content[0]), '</div>';
        ?>

        <?php endwhile; endif; ?
?>

This system gives 2 errors :

Warning: preg_split() expects at least 2 parameters, 1 given in C:\MAMP\htdocs\wordpress\wp-content\themes\Test\wp-vanilla\functions.php on line 125

Notice: Array to string conversion in C:\MAMP\htdocs\wordpress\wp-content\themes\Test\wp-vanilla\page-homepage.php on line 41

Can anyone help? I've tried various combinations.

2

2 Answers

1
votes

maybe u need use this function get_extended() WP Codex

it Return Values

(array) Post before ('main') and after ('extended').

0
votes

You can also try something like this :

$morestring = '<!--more-->';
$explode_content = explode( $morestring, $post->post_content );
$content_before = apply_filters( 'the_content', $explode_content[0] );
$content_after = apply_filters( 'the_content', $explode_content[1] );

Hope it helps you some extent.