public
Last active

Rotating headers plugin for Tarski

  • Download Gist
tarski_rotating_headers.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
<?php
/*
Plugin Name: Rotating Headers
Plugin URI: http://tarskitheme.com/
Description: Rotating headers plugin for Tarski.
Author: Benedict Eastaugh
Version: 1.0
Author URI: http://extralogical.net/
*/
 
/**
* This function mimics the output of the Tarski function tarski_headerimage,
* albeit using an image randomly chosen from the headers/ directory rather
* than a user-selected image.
*
* @uses get_tarski_option
* @uses get_bloginfo
*/
function tarski_rotating_headerimage() {
$dir = opendir(TEMPLATEPATH . '/headers');
$headers = array();
while ($current = readdir($dir))
if (($current != 'blank.gif') && !preg_match('/\-thumb\./', $current) && preg_match('/\.(jpg|png|gif)$/', $current))
$headers[] = $current;
$random = rand(0, count($headers) - 1);
$header_img_tag = sprintf('<img alt="%s" src="%s" />',
get_tarski_option('display_title') ? __('Header image', 'tarski') : get_bloginfo('name'),
get_bloginfo('template_directory') . '/headers/' . $headers[$random]);
if (!get_tarski_option('display_title') && !is_front_page())
$header_img_tag = sprintf(
'<a title="%s" rel="home" href="%s">%s</a>',
__('Return to main page', 'tarski'),
user_trailingslashit(get_bloginfo('url')),
$header_img_tag);
echo "<div id=\"header-image\">$header_img_tag</div>\n\n";
}
 
/**
* Setup function to work around the plugin/theme initialisation order problem.
* Removes the normal Tarski header image and adds a rotating header instead.
*/
function init_tarski_rotating_headers() {
remove_action('th_header', 'tarski_headerimage');
add_action('th_header', 'tarski_rotating_headerimage', 9);
}
 
add_action('init', 'init_tarski_rotating_headers');
 
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.