Advertisement
lberelson

Site 1 - rotate pic function TEST

Jul 23rd, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.40 KB | None | 0 0
  1.    
  2.  
  3.     <?php
  4.     /*
  5.      * Functions file
  6.      * Includes all necesary files
  7.      *
  8.      * @package custom
  9.      */
  10.      
  11.      
  12.     ini_set('display_errors', 'On');
  13.      
  14.     error_reporting(E_ALL);
  15.      
  16.      
  17.     function register_my_menus() {
  18.       register_nav_menus(
  19.         array(
  20.           'primary-menu' => __( 'Primary Menu' ),
  21.           'secondary-menu' => __( 'Secondary Menu' )
  22.         )
  23.       );
  24.     }
  25.     add_action( 'init', 'register_my_menus' );
  26.      
  27.      
  28.     function custom_widgets_init() {
  29.             register_sidebar(
  30.                     array(
  31.                             'name' => 'Rotate Pics Sidebar',
  32.                             'id' => 'rotate_pics',
  33.                             'before_widget' => '<div>',
  34.                             'after_widget' => '</div>',
  35.                             'before_title' => '<h2 class="rounded">',
  36.                             'after_title' => '</h2>',
  37.                     )
  38.             );
  39.            
  40.             register_sidebar(
  41.                     array(
  42.                             'name' => 'Articles Sidebar',
  43.                             'id' => 'articles',
  44.                             'before_widget' => '<div>',
  45.                             'after_widget' => '</div>',
  46.                             'before_title' => '<h2 class="rounded">',
  47.                     'after_title' => '</h2>',
  48.                     )
  49.             );
  50.     }
  51.      
  52.     // this function scans thru the directory received and loads the image file
  53.     // names into an array; Then returns a randome name to the caller
  54.     // If no directory is passed it will use the current dir
  55.      
  56.     function  GetImageName($DirName)
  57.             {
  58.                return "/wp-content/themes/custom/img/rotatepics/pic1.jpg";
  59.      
  60.     }  
  61.            
  62.             // function to print the random image
  63.            
  64.     function ShowRandomImg($size_x=300, $size_y=228)
  65.             {
  66.              $DirNm = "/wp-content/themes/custom/img/rotatepics";  // current directory
  67.               $ImgNm = GetImageName($DirNm);  // retrieve random image from current directory
  68.            
  69.              // print image (or if preferred change to return
  70.            
  71. echo "<img src=\"$ImgNm\" width=\"$size_x\" height=\"$size_y\"
  72.       alt=\"$ImgNm\">";
  73.              
  74.              // return $DirNm.$ImgNm;  // use this to simply return the image path
  75.            
  76.     }
  77.      
  78.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement