WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Flash video only in single post view (18 posts)

  1. Morten Rand-Hendriksen
    Member
    Posted 6 years ago #

    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?

  2. Kafkaesqui

    Posted 6 years ago #

    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?

  3. Morten Rand-Hendriksen
    Member
    Posted 6 years ago #

    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.

  4. Adam Brown
    Member
    Posted 6 years ago #

    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.

  5. Kafkaesqui

    Posted 6 years ago #

    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);
    ?>
  6. Morten Rand-Hendriksen
    Member
    Posted 6 years ago #

    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?

  7. Adam Brown
    Member
    Posted 6 years ago #

    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.

  8. Morten Rand-Hendriksen
    Member
    Posted 6 years ago #

    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

  9. Morten Rand-Hendriksen
    Member
    Posted 6 years ago #

    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.

  10. Adam Brown
    Member
    Posted 6 years ago #

    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.

  11. Kafkaesqui

    Posted 6 years ago #

    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); ?>
  12. Kafkaesqui

    Posted 6 years ago #

    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)); ?>
  13. Morten Rand-Hendriksen
    Member
    Posted 6 years ago #

    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?

  14. Kafkaesqui

    Posted 6 years ago #

    "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()));
    ?>
  15. Morten Rand-Hendriksen
    Member
    Posted 6 years ago #

    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!

  16. Morten Rand-Hendriksen
    Member
    Posted 6 years ago #

    never mind. I found the answer here: http://codex.wordpress.org/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

  17. Morten Rand-Hendriksen
    Member
    Posted 6 years ago #

    Just in case anyone was wondering what the hell I was up to I just took the new design live this afternoon:

    http://www.dabbler.ca

    Happy New Year

  18. Loughlin
    Member
    Posted 6 years ago #

    Great solution and may I add that Dabbler.ca looks fantastic!

Topic Closed

This topic has been closed to new replies.

About this Topic