• Hi Marty – I’ve checked out your plugin and so far so good. It looks like it can do what I need. However, I’m a bit new to all this and am not sure exactly how to do what I’m after.

    In your plugin description, you say that this plugin can help “…swap out flash for an image for iPhones.” I’m wondering how to do this. I have the code to my flash player, and I have the code to my image. I’m just not sure how to tell wordpress which one to display based on the browser.

    Any help you can provide would be most appreciated.

    Thanks,
    Michael

    http://wordpress.org/extend/plugins/php-browser-detection/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author MartyThornley

    (@martythornley)

    Hi Michael,
    This is pretty easy but you might have to look up PHP if loops if you are not familiar with them. It can be difficult to get code to display properly in here.

    But you just want to use the built in conditional statements to say “if this is an iPhone, display alternate content. Something like this:

    if (is_iphone()) {
    …code for a quicktime version of a movie (or image)…
    } else {
    …code for a flash version of a movie…
    }

    help on php if statements…
    http://php.net/manual/en/control-structures.if.php

    You can also look at some wordpress code for entering/exiting php code and html. a good example is the archive page on most themes, where they need to display different titles depending on what type of archive it is.

    I see the logic/code, but is this something that is in the theme/template file? Because PHP code doesn’t natively work in the Visual/HTML editor.

    My question is: Can the following be done???

    POST TITLE

    Body text. I think this video is the best.
    if (is_iphone()) {
    …code for a quicktime version of a movie (or image)…
    } else {
    …code for a flash version of a movie…
    }
    I hope you liked the video too. Have a great day.

    COMMENTS

    Plugin Author MartyThornley

    (@martythornley)

    Yes, this would have to be in the files themselves in a theme or plugin.

    And that is exactly how it is meant to be used 🙂

    You would just add it wherever you want. The text before and after would be tricky – you could use a custom field or the excerpt area.

    then do

    the_content();

    if (is_iphone()) {
    do stuff
    } else {
    do other stuff
    }

    the_excerpt(); (or custom field…)

    comments_template();

    You could maybe even add the video by custom fields so that the template would look like:
    the_content();

    if (is_iphone()) {
    echo iphone custom field
    } else {
    echo flash or alternate video custom field
    }

    the_excerpt(); (or custom field…)

    comments_template();

    That way you could use it for multiple pages/posts

    I follow, but I’m not a PHP pro… Is there no way to have shortcodes or something else instead? I think the straight PHP version (what you have now) definitely has a purpose, but it’s quite limiting. I know there are other plugins out there that are tailored to video, but I was thinking your plugin would be more flexible since it’s not JUST video.
    However, since your PHP can’t be inside “the_content();” I don’t think it’s going to work for what I’m needing. Even if I used custom fields, “the_content();” would come first, then your PHP results, then the comments area, right?
    Thanks.

    Plugin Author MartyThornley

    (@martythornley)

    No shortcodes at this time. It is really meant for developers.

    Beyond the instructions and the extra hints here, I can’t really offer any more. Not because I don’t want to. This just isn’t a place to give PHP lessons. There are plenty of great resources for php basics.

    I like the shortcode idea but it is really not a priority for me based on the way I use the plugin which is all in the theme files.

    If you want it in the content area I would suggest looking for a better video option that will work cross-browser.

    Clifford Paulick

    (@cliffpaulick)

    I understand your position and thank you for your reply. God bless!

    Thread Starter michaelmurf

    (@michaelmurf)

    Hi Marty – Thanks for all the tips and advice in this thread. I’ve been learning along the way and think I’ve found the solution that will work for me using your plugin. It would consist of creating 3 custom fields: (1) iPhoneVideo, (2) iPadVideo, and (3) Video. Each field would contain the video embed code (or image) for its corresponding device (which I would manage in the WordPress admin panel for each post). Then in the template file there would be an elseif statement that would check for iphone (and if iphone then display iphone code), if it wasn’t an iphone then it would check for ipad (and if it was ipad it would display the ipad code) and if it wasn’t iphone or ipad, then it would display whatever other code I wanted it to. I’m still pretty new at this and was wondering if you could check to see if I wrote this correctly below. Note that I am applying the_content filter so that I can include shortcodes in my custom fields (for iPhoneVideo, iPadVideo, and Video).

    <div class="video_main">
    <?php
    if (is_iphone()) {
    	echo apply_filters('the_content', get_post_meta($post->ID, 'iPhoneVideo', true));
    } elseif (is_ipad()) {
    	echo apply_filters('the_content', get_post_meta($post->ID, 'iPadVideo', true));
    } else {
    	echo apply_filters('the_content', get_post_meta($post->ID, 'Video', true));
    }
    ?>
    </div>

    Thanks!
    Michael

    Thread Starter michaelmurf

    (@michaelmurf)

    Hi again Marty – so I’ve been testing this on my WordPress site and cannot get it to work. Could it be that your plugin might be conflicting with my theme or another plugin?

    I know that the problem is not with either my custom fields (since when I echo those custom fields individually without the conditional statement, they show up fine). Further, the “else” code (which is designed to show my custom field “Video”) is what always gets displayed no matter what browser or device I’m using. In other words, it’s like the page just isn’t able to tell when I’m accessing it through my iphone (since when I view the source code on my iphone’s safari browser it showed me the “else” code for the “Video” custom field…and NOT the “if” code for the “iPhoneVideo” custom field).

    I’ve tried this on both regular WP and Multisite WP by uploading the plugin or specified files to the proper directories…and neither has worked.

    I am using WordPress 3.0.4 and version 2.0 of your plugin. One other point of confusion is that in your changelog for the plugin you have a version 2.1 referenced, but I couldn’t find anywhere to download 2.1.

    Any and all help is much appreciated.

    Best,
    Michael

    Plugin Author MartyThornley

    (@martythornley)

    Michael,

    Not sure there is anything in this plugin that COULD conflict with another, unless another was also defining functions with the same name.

    Usually when plugins conflict, it is because of javascript issues. This plugin is just a series of conditional statements. It doesn’t actually do anything except right at that point where you use the statement.

    As for the version numbers, I may have either mistyped the changelog or not updated the actual version number to match. I’ll check it out with my next update.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Plugin: PHP Browser Detection] Swap out flash video for iPhone’ is closed to new replies.