Here is a rough patch that I worked up for our site that allows me to maintain the slideshow just by adding/removing images from the images/slideshows directory. That is, the PHP just does an opendir() and readdir() to find all the image files in the directory, and them emits an HTML Only local images are allowed. for each one. That way, if we ever want to add/remove an image from the slideshow, we just add or remove a file from the slideshows directory -- there's no need to edit the theme page template.

The code is fairly rough, and leaves a lot of room for improvement, e.g.:

  • Add a text file for captions
  • Letting the user customize the directory where the slideshow files are located
  • Having specific timeframes where specific images can appear in the slideshow (e.g., image foo.jpg will only appear in the slideshow on June 8th, etc.)

Here's what I did -- hopefully it's of use to someone:

--- /home/bsfnhoa/drupal/danland/page.tpl.php	2010-11-19 08:42:44.000000000 -0600
+++ page.tpl.php	2011-06-01 05:12:55.000000000 -0500
@@ -80,10 +80,30 @@
 <?php if ($page['highlighted']) : ?><div id="slideshow-bottom">
 <div id="mission"><?php print render ($page['highlighted']); ?></div></div><?php endif; ?>
 <div class="slideshow">
-<img src="<?php print $base_path . $directory; ?>/images/slideshows/sea.jpg" width="950" height="355" alt="slideshow 1"/>
-<img src="<?php print $base_path . $directory; ?>/images/slideshows/noon.jpg" width="950" height="355" alt="slideshow 2"/>
-<img src="<?php print $base_path . $directory; ?>/images/slideshows/snow.jpg" width="950" height="355" alt="slideshow 3"/>
-</div>
+<?php
+$dir = drupal_get_path("theme", "danland") . "/images/slideshows";
+if (is_dir($dir)) {
+    $d = opendir($dir);
+    while (($f = readdir($d)) != false) {
+        if (!empty($f) && $f != "." && $f != "..") {
+            $files[] = $f;
+        }
+        continue;
+    }
+    closedir($d);
+
+    sort($files);
+    $i = 1;
+    foreach ($files as $file) {
+        # Best sizes are 950x355
+        $info = getimagesize("$dir/$file");
+        if ($info[3] != "") {
+            print("<img src=\"$base_path$directory/images/slideshows/$file\" $info[3] alt=\"slideshow $i\"/>\n");
+            ++$i;
+        }
+    }
+}
+?></div>
 </div>
 </div>
 <?php endif; ?>
--- /home/bsfnhoa/drupal/danland/maintenance-page.tpl.php	2011-01-06 01:45:39.000000000 -0600
+++ maintenance-page.tpl.php	2011-06-01 05:15:34.000000000 -0500
@@ -69,10 +69,30 @@
 <?php if ($content): ?><div id="slideshow-bottom">
 <div id="content-maintenance"><?php print $content; ?></div></div><?php endif; ?>
 <div class="slideshow">
-<img src="<?php print $base_path . $directory; ?>/images/slideshows/sea.jpg" width="950" height="355" alt="slideshow 1"/>
-<img src="<?php print $base_path . $directory; ?>/images/slideshows/noon.jpg" width="950" height="355" alt="slideshow 2"/>
-<img src="<?php print $base_path . $directory; ?>/images/slideshows/snow.jpg" width="950" height="355" alt="slideshow 3"/>
-</div>
+<?php
+$dir = drupal_get_path("theme", "danland") . "/images/slideshows";
+if (is_dir($dir)) {
+    $d = opendir($dir);
+    while (($f = readdir($d)) != false) {
+        if (!empty($f) && $f != "." && $f != "..") {
+            $files[] = $f;
+        }
+        continue;
+    }
+    closedir($d);
+
+    sort($files);
+    $i = 1;
+    foreach ($files as $file) {
+        # Best sizes are 950x355
+        $info = getimagesize("$dir/$file");
+        if ($info[3] != "") {
+            print("<img src=\"$base_path$directory/images/slideshows/$file\" $info[3] alt=\"slideshow $i\"/>\n");
+            ++$i;
+        }
+    }
+}
+?></div>
 </div>
 </div>
CommentFileSizeAuthor
#3 header-rotation-1175194-3.patch1.72 KBdoka
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

danpros’s picture

Status: Active » Needs review

Hi,

Thank you for the code. Change it to need review.

Dan

rthuey’s picture

experience level - first drupal site.

at first i was using bluehost.com's online code edit function. thinking the below was a bug with their editor. i have since tried this using Coda on my mac. the result is the same as stated below

i can add the second half of the patch and see no changes nor get any errors

whether i make the second half changes first or make only the changes from the first half of the patch. when i load it to the site and refresh, i get an error at line 86. if i then open the page that was just uploaded there is no code beyond line 85. which before the refresh there was more than 200 lines of code. weird to me. the last line that shows is 85.

if (is_dir($dir)) {

this is what i am starting with, that works before adding the patch.

<?php
// $Id: page.tpl.php,v 1.17.2.4 2010/11/19 14:42:44 danprobo Exp $
?>
<div <?php print danland_page_class($page['sidebar_first'], $page['sidebar_second']); ?>>
<div id="header">
<div id="header-wrapper">
	<?php if ($logo): ?> 
		<div id="logo-wrapper">
			<div class="logo">
				<a href="<?php print $base_path ?>" title="<?php print t('Home') ?>"><img src="<?php print $logo ?>" alt="<?php print t('Home') ?>" /></a>
			</div>
		</div><!-- end logo wrapper -->
	<?php endif; ?>
	<?php if ($site_name || $site_slogan) : ?>
		<div id="branding-wrapper">
			<?php if ($site_name) : ?>
				<?php if ($is_front) : ?>
					<h1 class="site-name"><a href="<?php print $base_path ?>" title="<?php print $site_name ?>"><?php print $site_name ?></a></h1>
				<?php endif; ?>
				<?php if (!$is_front) : ?>
					<h2 class="site-name"><a href="<?php print $base_path ?>" title="<?php print $site_name ?>"><?php print $site_name ?></a></h2>
				<?php endif; ?>
			<?php endif; ?>
			<?php if ($site_slogan) : ?>
				<div class='site-slogan'><?php print $site_slogan; ?></div>
			<?php endif; ?>
        	</div><!-- end branding wrapper -->
	<?php endif; ?>
	
	<?php if ($page['search_box']): ?>
		<div id="search-box">
			<?php print render ($page['search_box']); ?>
		</div><!-- /search-box -->
	<?php endif; ?>

	<?php if ($feed_icons): ?>
		<div class="feed-wrapper">
			<?php print $feed_icons; ?>
		</div>
	<?php endif; ?>

	<?php if (!$is_admin): ?>
		<div id="authorize">
      		      <ul><?php global $user; if ($user->uid != 0) { print '<li class="first">' .t('Logged in as '). '<a href="' .url('user/'.$user->uid). '">' .$user->name. '</a></li>'; print '<li><a href="' .url('user/logout'). '">' .t('Logout'). '</a></li>'; } else { print '<li class="first"><a href="' .url('user'). '">' .t('Login'). '</a></li>'; print '<li><a href="' .url('user/register'). '">' .t('Register'). '</a></li>'; } ?></ul>
		</div>
	<?php endif; ?>

      </div><!-- end header-wrapper -->
</div> <!-- /header -->
<div style="clear:both"></div>

<div id="menu">
<div id="rounded-menu-left"></div>
 <?php if ($main_menu || $page['superfish_menu']): ?>
      <div id="<?php print $main_menu ? 'nav' : 'superfish' ; ?>">
        <?php 
					     if ($main_menu) {
		          print theme('links__system_main_menu', array('links' => $main_menu));  
				      }
				      elseif (!empty($page['superfish_menu'])) {
				        print render ($page['superfish_menu']);
				      }
        ?>
      </div> <!-- end primary -->
    <?php endif; ?>
<div id="rounded-menu-right"></div>
</div> <!-- end menu -->
<div style="clear:both"></div>

<?php if($is_front): ?>
<div id="slideshow-wrapper"><table style="width:945px;margin-left:317px"><tr><td style="border-width:0px;">
<div class="slideshow-inner" style="float:left;width:450px;">
<div id="slideshow-preface">
 <?php if ($page['preface']): ?>
          <div id="preface">
            <?php print render ($page['preface']); ?>
          </div><!-- end preface -->
 <?php endif; ?>
</div>
<?php if ($page['highlighted']) : ?><div id="slideshow-bottom">
<div id="mission"><?php print render ($page['highlighted']); ?></div></div><?php endif; ?>
<div class="slideshow">
<img src="<?php print $base_path . $directory; ?>/images/slideshows/sea.jpg" width="450" height="355" alt="slideshow 1"/>
<img src="<?php print $base_path . $directory; ?>/images/slideshows/noon.jpg" width="450" height="355" alt="slideshow 2"/>
<img src="<?php print $base_path . $directory; ?>/images/slideshows/snow.jpg" width="450" height="355" alt="slideshow 3"/>
</div>
</div></td><td style="border-width:0px;">
<div class="slideshow-inner" style="float:right;width:450px;">
<div id="slideshow-preface">
 <?php if ($page['preface']): ?>
          <div id="preface">
            <?php print render ($page['preface']); ?>
          </div><!-- end preface -->
 <?php endif; ?>
</div>
<?php if ($page['highlighted']) : ?><div id="slideshow-bottom">
<div id="mission"><?php print render ($page['highlighted']); ?></div></div><?php endif; ?>
<div class="slideshow">
<img src="<?php print $base_path . $directory; ?>/images/slideshows/sea.jpg" width="450" height="355" alt="slideshow 1"/>
<img src="<?php print $base_path . $directory; ?>/images/slideshows/noon.jpg" width="450" height="355" alt="slideshow 2"/>
<img src="<?php print $base_path . $directory; ?>/images/slideshows/snow.jpg" width="450" height="355" alt="slideshow 3"/>
</div>
</div>
</td></tr></table>
</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
    $('.slideshow').cycle({
fx: 'fade' , timeout: 8000, delay: 2000});
});</script>
<?php endif; ?>

 <?php if($page['preface_first'] || $page['preface_middle'] || $page['preface_last']) : ?>
    <div style="clear:both"></div>
    <div id="preface-wrapper" class="in<?php print (bool) $page['preface_first'] + (bool) $page['preface_middle'] + (bool) $page['preface_last']; ?>">
          <?php if($page['preface_first']) : ?>
          <div class="column A">
            <?php print render ($page['preface_first']); ?>
          </div>
          <?php endif; ?>
          <?php if($page['preface_middle']) : ?>
          <div class="column B">
            <?php print render ($page['preface_middle']); ?>
          </div>
          <?php endif; ?>
          <?php if($page['preface_last']) : ?>
          <div class="column C">
            <?php print render ($page['preface_last']); ?>
          </div>
          <?php endif; ?>
      <div style="clear:both"></div>
    </div>
    <?php endif; ?>

<div style="clear:both"></div>
<div id="wrapper">

    <?php if ($page['sidebar_first']): ?>
      <div id="sidebar-left" class="column sidebar"><div class="section">
        <?php print render($page['sidebar_first']); ?>
      </div></div> <!-- end sidebar-first -->
    <?php endif; ?>
<div id="content">
			<a id="main-content"></a>
			<?php if ($page['content_top']) : ?><div class="content-top"><?php print render ($page['content_top']); ?></div>
			<?php endif; ?>
			<?php if (!$is_front) print $breadcrumb; ?>
			<?php if ($show_messages) { print $messages; }; ?>
      		<?php print render($title_prefix); ?>
      			<?php if ($title): ?>
        				<h1 class="title" id="page-title">
         			 		<?php print $title; ?>
        				</h1>
     				 <?php endif; ?>
      		<?php print render($title_suffix); ?>
      		<?php if ($tabs): ?>
        			<div class="tabs">
          				<?php print render($tabs); ?>
        			</div>
      		<?php endif; ?>
      		<?php print render($page['help']); ?>
      		<?php if ($action_links): ?>
        			<ul class="action-links">
          				<?php print render($action_links); ?>
        			</ul>
      		<?php endif; ?>
		      <?php if ($page['content']) : ?><div class="content-middle"><?php print render ($page['content']); ?></div>
			<?php endif; ?>
			<?php if ($page['content_bottom']) : ?><div class="content-bottom"><?php print render ($page['content_bottom']); ?></div>
			<?php endif; ?>

</div> <!-- end content -->

    <?php if ($page['sidebar_second']): ?>
      <div id="sidebar-right" class="column sidebar"><div class="section">
        <?php print render($page['sidebar_second']); ?>
      </div></div> <!-- end sidebar-second -->
    <?php endif; ?>
<div style="clear:both"></div>
</div> <!-- end wrapper -->


<?php if($page['bottom_first'] || $page['bottom_middle'] || $page['bottom_last']) : ?>
    <div style="clear:both"></div>
    <div id="bottom-teaser" class="in<?php print (bool) $page['bottom_first'] + (bool) $page['bottom_middle'] + (bool) $page['bottom_last']; ?>">
          <?php if($page['bottom_first']) : ?>
          <div class="column A">
            <?php print render ($page['bottom_first']); ?>
          </div>
          <?php endif; ?>
          <?php if($page['bottom_middle']) : ?>
          <div class="column B">
            <?php print render ($page['bottom_middle']); ?>
          </div>
          <?php endif; ?>
          <?php if($page['bottom_last']) : ?>
          <div class="column C">
            <?php print render ($page['bottom_last']); ?>
          </div>
          <?php endif; ?>
      <div style="clear:both"></div>
    </div> <!-- end bottom first etc. -->
    <?php endif; ?>


 <?php if($page['bottom_1'] || $page['bottom_2'] || $page['bottom_3'] || $page['bottom_4']) : ?>
    <div style="clear:both"></div><!-- Do not touch -->
    <div id="bottom-wrapper" class="in<?php print (bool) $page['bottom_1'] + (bool) $page['bottom_2'] + (bool) $page['bottom_3'] + (bool) $page['bottom_4']; ?>">
          <?php if($page['bottom_1']) : ?>
          <div class="column A">
            <?php print render ($page['bottom_1']); ?>
          </div>
          <?php endif; ?>
          <?php if($page['bottom_2']) : ?>
          <div class="column B">
            <?php print render ($page['bottom_2']); ?>
          </div>
          <?php endif; ?>
          <?php if($page['bottom_3']) : ?>
          <div class="column C">
            <?php print render ($page['bottom_3']); ?>
          </div>
          <?php endif; ?>
          <?php if($page['bottom_4']) : ?>
          <div class="column D">
            <?php print render ($page['bottom_4']); ?>
          </div>
          <?php endif; ?>
      <div style="clear:both"></div>
    </div><!-- end bottom -->
    <?php endif; ?>

<div style="clear:both"></div>
<div id="footer-wrapper">
<?php if($page['footer']): ?>
<div id="footer">
 <?php print render ($page['footer']); ?>
</div>
<?php endif; ?>
<?php if($secondary_menu) : ?>
<div id="subnav-wrapper">
<?php print theme('links__system_secondary_menu', array('links' => $secondary_menu, 'attributes' => array('id' => 'subnav', 'class' => array('links', 'clearfix')))); ?>
</div>
<?php endif; ?>
</div> <!-- end footer wrapper -->

<div style="clear:both"></div>
<div id="notice"><p>Theme by <a href="http://www.danetsoft.com">Danetsoft</a> and <a href="http://www.danpros.com">Danang Probo Sayekti</a> inspired by <a href="http://www.maksimer.no">Maksimer</a></p></div>
</div>
doka’s picture

please find my patch: it takes all the pictures from /images/slideshows, and rotates them.

diff --git a/page.tpl.php b/page.tpl.php
index 46ec3ab..2e81c51 100644
--- a/page.tpl.php
+++ b/page.tpl.php
@@ -80,9 +80,27 @@
 <?php if ($page['highlighted']) : ?><div id="slideshow-bottom">
 <div id="mission"><?php print render ($page['highlighted']); ?></div></div><?php endif; ?>
 <div class="slideshow">
-<img src="<?php print $base_path . $directory; ?>/images/slideshows/sea.jpg" width="950" height="355" alt="slideshow 1"/>
-<img src="<?php print $base_path . $directory; ?>/images/slideshows/noon.jpg" width="950" height="355" alt="slideshow 2"/>
-<img src="<?php print $base_path . $directory; ?>/images/slideshows/snow.jpg" width="950" height="355" alt="slideshow 3"/>
+
+<!-- start header rotation -->
+<?php
+define('DANLAND_HEADER_PATH',
+       (is_dir(path_to_theme() . '/images/slideshows') ?
+       path_to_theme() : drupal_get_path('theme', 'danland')) . '/images/slideshows');
+
+/** The mask to use when listing the headers directory. */
+define('DANLAND_HEADER_IMG_MASK',
+       '/\.jpg$|\.JPG$|\.jpeg*|\.JPEG*|\.gif$|\.GIF$|\.png$|\.PNG$/');
+
+    $files = file_scan_directory(DANLAND_HEADER_PATH,
+                                 DANLAND_HEADER_IMG_MASK,
+                                 array('.', '..', 'CVS', '.svn'));
+    foreach ($files as $filename => $data) {
+?>
+<img src="<?php print $filename; ?>" width="950" height="355" alt="slideshow"/>
+<?php } ?>
+
+<!-- end header rotation -->
+
 </div>
 </div>
 </div>
@@ -224,4 +242,4 @@
 
 <div style="clear:both"></div>
 <div id="notice"><p>Theme by <a href="http://www.danetsoft.com">Danetsoft</a> and <a href="http://www.danpros.com">Danang Probo Sayekti</a> inspired by <a href="http://www.maksimer.no">Maksimer</a></p></div>
-</div>
\ No newline at end of file
+</div>

  • jcnventura committed f41919b on 7.x-1.x authored by doka
    Issue #1175194 by doka: Simply use all images in slideshow dir
    
jcnventura’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.