Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Functions file
- * Includes all necesary files
- *
- * @package custom
- */
- ini_set('display_errors', 'On');
- error_reporting(E_ALL);
- function register_my_menus() {
- register_nav_menus(
- array(
- 'primary-menu' = __( 'Primary Menu' ),
- 'secondary-menu' = __( 'Secondary Menu' )
- )
- );
- }
- add_action( 'init', 'register_my_menus' );
- function custom_widgets_init() {
- register_sidebar(
- array(
- 'name' = 'Rotate Pics Sidebar',
- 'id' = 'rotate_pics',
- 'before_widget' = '<div',
- 'after_widget' = '</div',
- 'before_title' = '<h2 class="rounded"',
- 'after_title' = '</h2',
- )
- );
- register_sidebar(
- array(
- 'name' = 'Articles Sidebar',
- 'id' = 'articles',
- 'before_widget' = '<div',
- 'after_widget' = '</div',
- 'before_title' = '<h2 class="rounded"',
- 'after_title' = '</h2',
- )
- );
- }
- // this function scans thru the directory received and loads the image
- file // names into an array; Then returns a random name to the caller
- // If no directory is passed it will use the default dir
- function GetImageName($DirName)
- {
- $Img = array(); // define array
- // jpg
- foreach (glob("$DirName/*.jpg") as $filename)
- {
- if (is_readable($filename))
- $Img[] = $filename; // found image file
- }
- // png
- foreach (glob("$DirName/*.png") as $filename)
- {
- if (is_readable($filename))
- $Img[] = $filename; // found image file
- }
- // gif
- foreach (glob("$DirName/*.gif") as $filename)
- {
- if (is_readable($filename))
- $Img[] = $filename; // found image file
- }
- $Imgcount = sizeof($Img) - 1; // the index is zero-based
- if ($Imgcount <= 0)
- return "/wp-content/themes/custom/img/rotatepics/pic1.jpg";
- else
- {
- $rand_image_ix = rand(0,$Imgcount);
- return $Img[$rand_image_ix]; // return name of image
- }
- }
- // function to print the random image
- function ShowRandomImg($size_x=300, $size_y=228)
- {
- $DirNm = "/wp-content/themes/custom/img/rotatepics"; // current
- directory
- if (is_front_page() || is_page('contact') )
- {
- $DirNm = $DirNm . "/contact";
- $ImgNm = GetImageName($DirNm); // retrieve random image from
- directory "contact"
- }
- elseif (is_page('references')
- {
- $DirNm = $DirNm . "/references";
- $ImgNm = GetImageName($DirNm); // retrieve random image from
- directory "references"
- }
- elseif (is_page('services')
- {
- $DirNm = $DirNm . "/services";
- $ImgNm = GetImageName($DirNm); // retrieve random image from
- directory
- "services"
- }
- else
- {
- $ImgNm = GetImageName($DirNm); // retrieve random image from
- current directory
- }
- // print image (or if preferred change to return
- $ImgPath = $DirNm . "/" . $ImgNm;
- echo "<img src=\"$ImgNm\" width=\"$size_x\" height=\"$size_y\"
- alt=\"$ImgNm\"> ";
- // return $DirNm.$ImgNm; // use this to simply return the image path
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement