Want to take part in these discussions? Sign in if you have an account, or apply for one below
Vanilla 1.1.10 is a product of Lussumo. More Information: Documentation, Community Support.
[html]
<script type="text/javascript">
var titleElementId = "head";
var imgPath = "/fp-interface/themes/leggero-paul/imgs/topphotos/";
var imagesToUse = new Array("ahorn.jpg","...", ...);
var imageSwitchIndex = Math.floor(Math.random()*imagesToUse.length);
i = imageSwitchIndex;
var elem = document.getElementById(titleElementId);
if(elem != null) {
elem.style.backgroundImage = "url('"+imgPath+imagesToUse[i]+"')";
elem.style.backgroundRepeat = "no-repeat";
if (elem.addEventListener){
elem.addEventListener('click', switchImg, false);
} else if (elem.attachEvent){
elem.attachEvent('onclick', switchImg);
}
}
function switchImg() {
var imageSwitchIndex = Math.floor(Math.random()*imagesToUse.length);
i = imageSwitchIndex;
var elem = document.getElementById(titleElementId);
if(elem != null) {
elem.style.backgroundImage = "url('"+imgPath+imagesToUse[i]+"')";
elem.style.backgroundRepeat = "no-repeat";
}
}
</script>
[/html]
<?php
/*
Plugin Name: randomheadimg
Version: 0.1
Plugin URI: http://blog.wbou.de
Author: Paul Wellner Bou
Author URI: http://blog.wbou.de
*/
add_action('wp_head', 'plugin_randomheadimg_head', 0);
function plugin_randomheadimg_head() {
$imgdir = dirname(__FILE__).DIRECTORY_SEPARATOR.'imgs'.DIRECTORY_SEPARATOR;
$dh = opendir($imgdir);
$imgs = array();
while (($file = readdir($dh)) !== false) {
if(is_dir($imgdir.$file) || $file == '.' || $file == '..')
continue;
if(preg_match("/\.(jpg|png|gif)$/i", $file))
$imgs[] = $file;
}
if(count($imgs) == 0)
return;
$selected_index = rand(1, count($imgs));
$selected_img = plugin_geturl('randomheadimg').'imgs/'.$imgs[$selected_index];
echo <<<RANDOMHEADIMGHEAD
<!-- start of randomheadimg -->
<style type="text/css"> #head { background-image: url('$selected_img') !important; } </style>
<!-- end of randomheadimg -->
RANDOMHEADIMGHEAD;
}
?>what about a plagin for random image header by category? :D
<?php
/*
Plugin Name: GlobalCategoryId
Version: 1.0
Plugin URI: http://flatpress.org
Description: Inject a global smarty variable $global_category
Author: NoWhereMan
Author URI: http://flatpress.org
*/
add_filter('wp_head', 'plugin_gi_head');
function plugin_gi_head() {
global $smarty, $fpdb;
// get query object
$q =& $fpdb->getQuery();
// default category is 0 ("unfiled" or "all")
$category = 0;
// is single entry (comments or permalink)
if ($q->params->id) {
list($id, $e) = $q->peekEntry();
// get FIRST category or returns 0 (unfiled)
if (isset($e['categories']))
$category = $e['categories'][0];
} elseif (isset($q->params->category)) {
// if we are displaying a single category
$category = $q->params->category;
}
$smarty->assign('global_category', $category);
}<body class="category-{$global_category}">
// other stuff
body.category-0 #header {
background: url(../imgs/image-for-category-0.png);
}
body.category-123 #header {
background: url(../imgs/image-for-category-123.png);
}
...
Posted By: paulBetter than my approach. Nevertheless, I uploaded my version to my page, too.
The images has to be named.jpg (or .jpg) and default.jpg. All lowercase and white space characters stripped. They have to be saved into the plugin's img directory, similar to my other header plugin.
http://blog.wbou.de/flatpress
Posted By: lantaca another question: is possible to assign a category to the static page?
1 to 22 of 22