I want to insert <!--nextpage--> after every 10 image tags in a wordpress post (if there are 30 images, I'll get 3 pages), but I can't seem to figure out how to do it. I found a php function that does it for paragraphs, so I tried to rewrite it, but I don't know how to target the img tag, and can't find anything about that either.. I'm stuck.
<?php
$show_after_img = 2;
$content = apply_filters('the_content', $post->post_content);
if(substr_count($content, '<img>') > $show_after_img)
{
$contents = explode("<img>", $content);
$img_count = 1;
foreach($contents as $content)
{
echo $content;
if($img_count == $show_after_img)
{
?>
<p class="page-break"></p>
<?php
}
echo "<img>";
$img_count++;
}
}
?>
Aucun commentaire:
Enregistrer un commentaire