• Resolved nzahn

    (@nzahn)


    Well … I am having a slight problem (of course); I am trying to filter content and explode it – it works great in 2.7 Kubrik and yes it does not work in 2.8 Kubrik; the code in its basic looks like this:

    `<?php $content = apply_filters(‘the_content’, $post->post_content );
    $paragraphs = explode(‘<p>’, $content);
    $i = 0;
    foreach ($paragraphs as $number){
    $i++;
    $q = $i – 1;
    if ($i == 0) {
    echo $q.$number;
    }
    }?>`

    the content looks like this:

    <p>First Paragraph</p><p>Second Paragraph</p>

    If you do this it should not display anything – in 2.7 it behaves right; 2.8 shows content from the $post->post_content which makes me think that apply_filters does not do its work correctly; I tried looking it up, but nothing found in the documentation of wordpress 2.8; any help would be wonderful. Thanks upfront.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter nzahn

    (@nzahn)

    All right … solved it; if someone is interested here is the fixed code:

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

    <?php $content = $post->post_content;
    $paragraphs = explode(‘<p>’, $content);
    $i = 0;
    foreach ($paragraphs as $number){
    $i++;
    $q = $i – 1;
    if ($i == 0) {
    echo $q.$number;
    }
    }?>

    <?php endwhile; else: ?>
    <p><?php _e(‘Sorry, no posts matched your criteria.’); ?></p>
    <?php endif; ?>
    simple enough? btw. this does column splitting by <p> can be any tag though; hope this helps anyone.

    If you’re displaying the content after using explode, you’re actually invalidating your code…

    You’re removing the opening tags and not replacing them.

    echo $q.'<p>'.$number; // Fix missing opening paragraph tags

    I assume the use of explode is so you can split the content up. If that’s not really the case and you’re just counting the paragraphs then there’s easier ways.

    Here’s one..

    $paragraphs = explode('<p>',$post->post_content);
    $paracount = count($paragraphs); unset($paragraphs);
    echo $paracount; unset($paracount);

    If that’s not what you’re attempting to do then why are you dividing the content up into an array?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘apply_filters content in wordpress 2.8’ is closed to new replies.