Reputation: 9
On single.php this is used to display post content:
<div class="post-content">
<?php the_content(); ?>
</div>
How could i break the content(without using more tag in WP editor) so it looks like this:
<div class="post-content">
first 100 letters of the post
</div>
<div class="post-content">
remaining part of the post
</div>
I need to do this because i will add a slider in between those 2 parts.
Upvotes: 0
Views: 442
Reputation: 1263
if you wanna to split content by word count use wp_trim_words
function.
here is an example of code that you can use it (I didn't check it).
<?php $content = get_the_content();?>
$first_slice = wp_trim_words($content,100);
$second_slice = substr($content,strlen($first_slice),strlen($content));
echo '<div class="post-content">'.wpautop($first_slice).'</div>';
echo '<div class="post-content">'.wpautop($second_slice).'</div>';
Upvotes: 1
Reputation: 116
<?php $content = get_the_content(); ?>
<div class="post-content">
<?php echo substr($content, 0, 100); ?>
</div>
<div class="post-content">
<?php echo substr($content, 101, strlen($content)); ?>
</div>
Upvotes: 0