As you might know by now, I'll be presenting a session at Do It With Drupal on December 10. If you didn't know, get a ticket, and then come back here! I'm currently building a YouTube clone with Drupal in my spare time. When I'm done with it all, I get to come talk with you folks about how I did it.
Obviously, I'm not going to replicate the entire YouTube site. There comes a point of diminishing returns, especially for something I'm doing for fun. So I have to pick and choose what pieces to build. (For the record, there will also be parts that I believe will be improvements on YouTube; not difficult, since I'm building it with Drupal.)
The video slide show on YouTube's front page would have been a case-in-point. It's built in Flash, and I figured I would skip it, since it's just eye candy. Normally for that, I would use jCarousel or Views Slideshow, but neither replicates YouTube's functionality, and they seemed out of place for this slider that slides 5 videos at a time. But then I remembered someone telling me about the jQuery Cycle plug-in, by the same author of the jQuery Media plug-in.
How I Did It (in 20 minutes, nonetheless)...
The solution isn't completely straight-forward, because of needing to switch out 5 items at a time. However, Views 2 has some really great tools to help out there.
After installing the modules I need (jQuery Plugins, which includes the jQuery Cycle plug-in, and jQ, which offers a unified developer's library and will offer a hopefully easy upgrade to Drupal 7's upcoming core Centralized jQuery plug-in manager), I rolled up my sleeves (and Firebug for examining the style elements).
First, I built a view with 25 nodes, so it could be easily divided by the 5 thumbnails in the slide show. It's sorted by the daily most popular. I'm not sure how YouTube chooses their "Videos being watched right now", but I figure this will give a fair rendition.
While building the view, you'll notice a little link labeled Theme: Information. Become friends with Theme: Information. She will help you solve some otherwise tough problems if you get to know her.
I clicked on that little link, and was presented with a long list of candidate theme template overrides. I took a quick look over, and decided on a Style output template, which prints out each row of data. I then simply overrode that template to split the rows into groups of five, and to invoke the jQuery Cycle plug-in.
<?php
// $Id$
/**
* @file views-view-unformatted--videos--block-4.tpl.php
* Default simple view template to display a list of rows.
* The filename corresponds to this particular view; if reproducing on your own site,
* you'll need to choose an appropriate file from the Style output group of Theme: Information.
*
* @ingroup views_templates
*/
// Make sure the jQ module is enabled, so we don't get PHP errors if we disable it in the future.
if (module_exists('jq')) {
// I'm using jq_add here. It assumes you have the jQuery Cycle plug-in installed. That plug-in
// comes bundled with the jQuery Plugins module, but you could also just drop it into a
// /plugins or /sites/example.com/plugins folder and call it with the same method.
jq_add('cycle');
// Here's the actual call for our cycle slide show plug-in.
// I'm using the 'shuffle' effect, shifting the images w/ top & left, slowing it from the default
// with 'timeout', and using 'pause' to allow a pause on mouse hover. There are lots of cool
// effects; see the plug-in home at malsup.com/jquery/cycle/.
$js = <<<js
$('#cycle-videos-$id').cycle({
fx: 'shuffle',
shuffle: {
top: 30,
left: 15,
},
pause: 1,
timeout: 10000
});
js;
// Make it degrade gracefully in non-javascript browsers.
$js = "if (Drupal.jsEnabled) { $(document).ready(function() { $js }); }";
drupal_add_js($js, 'inline');
}
?>
<?php if (!empty($title)): ?>
<h3><?php print $title; ?></h3>
<?php endif; ?>
<div id="cycle-videos-<?php print $id; ?>">
<?php
$count = 0;
$row_count = 0;
// Cycle through all our divs.
while ($count < sizeof($rows)) {
// Each of these divs will be a separate frame in the cycle slide show.
print '<div id="cycle-videos-'. $id .'-'. ($row_count++) .'" class="cycle-videos">';
$inner_count = 0;
// Now display 5 rows of data, each of which is just a thumbnail in this case.
// Note this slide show is not limited to images. It could be text, videos, whatever.
while ($inner_count < 5 && $count < sizeof($rows)) {
print '<div class="'. $classes[$id] .'">'. $rows[$count++] ."</div>\n";
$inner_count++;
}
print "</div>\n";
}
?>
</div>Finally, I cleaned up the CSS. That took over half of the time. I'm not going to explain that here. If you want to know how I did it, you can use Firebug to look at it from your browser.
That's it! You can see the results at YouDrup. (That site is still in progress, so wear your construction hat.)
I look forward to seeing you at Do It With Drupal next month! (I'll also be at DrupalCamp Philly next week and at DrupalCon DC in the spring if you can't make that.)
nice article mate i will bookmark the page and i am awaiting more aticles cheers http://www.consolemodz.com
thanks for all the links you have shared here, guys! I really appreciate them!
thanks for the contribution, I'll look at the amazon for the book :)
Drupal is more professional than Joomla as far as development is concerned.
Joomla is great for somebody who wants all the bells and whistles and is willing to spend the next 6 months forcing them to work.
Wordpress is good for people who want to do business and are not interested in development.
I personally feel that Wordpress will continue to do what it has set out to do. I feel Joomla may fall down the same security path as phpNuke did by offering under experienced programmers access to things which they aren't going to be able to secure or support properly. Drupal will take alot of good programmers and make them better programmers I think. Although I am not a big fan of the object oriented paradigm. However I do think for the real programming professionals there are better options. But the market seems to be shaping thier destiny with drupal.
All things aside. Make sure what ever add-ons you have come with a professional commerical backing. History has proven time and time again that the non-commercially supported projects die out.
Why cant the "drupal community" put up so contrib theme that just don't flat-out suck? Even this site is using a drab mind-numbingly boring out of the box theme. When it comes to themes or templates, Joomla is light-years ahead of Drupal - which has me scratching my head, Where are all the Drupal theme designers??