0

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 Answers 2

1

maybe u need use this function get_extended() WP Codex

it Return Values

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

thanks jenis, This does help .... does the above code get placed in functions.php? what would i need to place in my index.php , i.e. were I would like the content to show up?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.