最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Get first two paragraphs inside one div, and then get the rest under another?

programmeradmin1浏览0评论

I have to define non-paywall and paywall text in the_content(); per google rules, so far I tried:

     $content = apply_filters('the_content', get_the_content());
     $str = substr( $content, 0, strpos( $content, '</p>' ) + 4 );
     $str = strip_tags($str, '<a><strong><em>');
     $first_slice = $str;
     $second_slice = substr($content,strlen($first_slice),strlen($content));
     echo '<div class="non-paywall">'. html_entity_decode ( $first_slice ) .'</div>';
     echo '<div class="paywall">'. html_entity_decode ( $second_slice ) .'</div>';

This shows first paragraph well, and ends word without trimming its characters, and then it repeats one word in second slice and continues text. This is what I tried, but not actually what I need.

I need this structure:

    <div class="non-paywall">
    Paragraph 1
    Paragraph 2
    </div>

    <div class="paywall">
    Paragraph 3
    ...
    To the end.
    </div>
发布评论

评论列表(0)

  1. 暂无评论