• Resolved mor10

    (@mor10)


    I am building a blog that features a Brightcove video player on the index page that plays a series of videos. I also want to be able to write posts with individual videos in them. however, I only want the individual videos to show up if people go to the posts in single post view because otherwise the index page would contain up to 10 separate flash video files at the same time.

    Is there some way of hacking WordPress to make a function similar to the pagebreak –more– function but above the other content or do I have to put my videos below the cutline?

Viewing 15 replies - 1 through 15 (of 17 total)
  • Should be easy to code a little replacement for the_content() which excludes video content. How are you ’embedding’ the player, through HTML embed, javascript, or what?

    Thread Starter mor10

    (@mor10)

    it’ll probably be html embedding. I tried the javascript option but it caused some weird problems. I can use either – whichever will allow what I want to do.

    JS would make this trick easy. In your header.php, do something like this:

    <?php if (is_single()){ ?>
    <script type="text/javascript"><!--
    var yes_videos = true;
    // -->
    </script>
    <?php } ?>

    Then just have your JS check whether yes_videos is true before placing the videos.

    JS has the added advantage of not giving the “Click to activate this content” message in IE when you mouse over the flash player.

    Good one adam.

    Here’s something for <embed>; replace the_content() in your template with:

    <?php
    $content = preg_replace('%<embed.*<\/embed>%smUi', '', $post->post_content);
    echo apply_filters('the_content', $content);
    ?>

    Thread Starter mor10

    (@mor10)

    Kafkaesqui: What exactly does this do?

    Here’s something for <embed>; replace the_content() in your template with:

    <?php
    $content = preg_replace(‘%<embed.*<\/embed>%smUi’, ”, $post->post_content);
    echo apply_filters(‘the_content’, $content);
    ?>

    and do I replace it only in the single post template or globaly?

    It will look for any <embed> tags in your post and remove it. You would only want to do this in index.php, NOT in single.php.

    You would want to do something similar for <object> tags, probably.

    Thread Starter mor10

    (@mor10)

    Fantastic! I inserted this code in the index.php file and it works:

    <?php $content = preg_replace('%<object.*<\/object>%smUi', '', $post->post_content);
    $content = preg_replace('%<embed.*<\/embed>%smUi', '', $post->post_content);
     echo apply_filters('the_content', $content); ?>

    thanks

    Thread Starter mor10

    (@mor10)

    Strike that. it shows an empty object box in IE. If I only insert the object replace it works in both IE and FireFox but leaves a blank line where the video should be. If I only insert the embed replace it leaves an empty object box in IE.

    I know there is something wrong in my code, the question is what.

    The fix:

    <?php $content = preg_replace('%<object.*<\/object>%smUi', '', $post->post_content);
    $content = preg_replace('%<embed.*<\/embed>%smUi', '', $content);
     echo apply_filters('the_content', $content); ?>

    Note that the second $post->post_content should be $content, that way the second preg_replace builds on the results of the first preg_replace rather than starting all over.

    A single preg_replace() is all you need:

    <?php $content = preg_replace('%<(object|embed).*<\/(object|embed)>%smUi', '', $post->post_content);
    echo apply_filters('the_content', $content); ?>

    On a second look the above could leave </object> (since it should stop processing when finding </embed> first).

    Since <embed> should be nested in an <object> anyways (for embedding the Brightcove player), it would be cleaner to match on that alone. Here’s a one-liner:

    <?php echo apply_filters('the_content', preg_replace('%<object.*<\/object>%smUi', '', $post->post_content)); ?>

    Thread Starter mor10

    (@mor10)

    just a quick follow-up: it seems like this code kills the <!–more–> functionality leaving the full posts on the front page. I’m not 100% sure that this is the cause but I’m guessing it is. if so, how do I fix this so that I only get the content I want on the front?

    it seems like this code kills the <!–more–> functionality leaving the full posts on the front page.

    It does bypass the_content() functionality such as handling the ‘more’ quicktag and post password handling. Try this:

    <?php
    echo apply_filters('the_content', preg_replace('%<object.*<\/object>%smUi', '', get_the_content()));
    ?>
    Thread Starter mor10

    (@mor10)

    It does bypass the_content() functionality such as handling the ‘more’ quicktag and post password handling. Try this:

    <?php
    echo apply_filters(‘the_content’, preg_replace(‘%<object.*<\/object>%smUi’, ”, get_the_content()));
    ?>

    ah.. almost there. now how do I get it to say “Get the whole story” instead of saying “(more…)”?

    thanks for your help btw!

    Thread Starter mor10

    (@mor10)

    never mind. I found the answer here: https://codex.www.ads-software.com/Customizing_the_Read_More

    Thank you all very much for your help. This issue is resolved . I’ll post the final product when it goes online on January 1st.

    Mor10

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Flash video only in single post view’ is closed to new replies.