Hi - I'm trying to do something outside my php skill level, but I'm doing so purposely to try to stretch and learn. I'd like someone to either check/correct my (probably hideous) attempt at coding this, or suggest a more elegant solution than the one my tiny brain came up with.
This is what I'd like the site to do:
A client of mine is going to have video blog posts (a vlog), separate from regular blog posts. In the sidebar, a thumbnail of the most recent vlog post will appear as a link to the single/permanent url of the post. Using a plugin, that I can easily do.
However, she wants to make sure iPhone users aren't left out, so she plans to have two videos available, one in Flash and one in mp4.
My plan, to make it as quick and easy for the user as possible, is for my client to make two blog posts for each video (they won't be pulled into the regular blog). She can tag or categorize them to differentiate. Then I'd like the blog to detect the browser (I'm using the PHP Browser Detection plugin to do this) then pull into the sidebar either the link to the Flash version of the post or the mp4 version, depending on the results. The link would go straight to the correct version of the video without the user having to click a second link if they don't have Flash.
PHP Browser Detection creates some custom functions for you to use (like "<?php if ( is_iphone($version) ) { do stuff }; ?>"). Using this, I created the following which 1) I fully acknowledge could be a code abomination and 2) unsurprisingly, causes the sidebar (and the footer) not to appear at all.
<!-- Right Sidebar Start -->
<div id="sidebar_right">
<div class="widget_stray_quotes">
<h2>See the latest vlog</h2>
<!-- Check the browser to get the link to the correct vlog format -->
<?php if (is_iphone()) {
//Get the link to the mp4 post ?>
<?php if (have_posts()) :
(query_posts('tag=vlog_mp4&posts_per_page=1');?>
<?php while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php }
else {
//Get the link to the Flash post ?>
<?php if (have_posts()) :
(query_posts('tag=vlog_flash&posts_per_page=1'));?>
<?php while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php endif; ?>
<!-- end vlog function -->
</div>
Anyone have an idea what's not working/a better way to go?