x
Toggle Content    Register or Login  -  June 24, 2018, 4:13 pm  
Toggle Content Commercial Themes
This is an opportunity for you to preview TCD commercial themes. All themes seen here can be purchased from the store.
Toggle Content User Info

Welcome Anonymous

Toggle Content Navigation
Toggle Content Project Status
Support Forums » DragonflyCMS » Tips & Tricks » Header - Random Image Rotator by Kristin
Please use the forum search before making a post. Your question might have been previously answered.

Header - Random Image Rotator by Kristin
Some of the best non-standard tricks for your site all in one location.


Post new topic   Reply to topic    Forum Index » Tips & Tricks Printer Friendly Page

View previous topic :: View next topic  
Author Message
Lead Developer


PostPosted: Tue Jun 05, 2007 11:16 am Reply with quote

Credit for this code goes to Kristin of Dragonflied.com used in cpg_xsport.

Step 1:
Create a folder/directory called "random" in your theme's images directory and place all the images you want in there.
For example the path you'll be using to call your random images will be: yourtheme/images/random/01.jpg

Step 2:
In yourtheme/theme.php directly above where you assign variables (as is customary with most header modification such as header login, header pm notification, etc...) place the following code:

Code:
// random image at top in header
$array = array('01.jpg', '02.jpg', '03.jpg');
$image = rand(0, count($array)-1);

    $cpgtpl->assign_vars(array(
    'CSS_FILE'     => ereg('MSIE', $_SERVER['HTTP_USER_AGENT']) ? 'ie' : 'style',
Don't forget to specify the image filenames you want in the array. Replace 01.jpg etc... with your images.

Assign the variable:
Code:
'RAND_IMG' 	   => $array[$image],

Step 3:
In yourtheme/template/header.html (or whatever template file you want to have a rotating image use the following code.
Code:
<img src="{THEME_PATH}/images/random/{RAND_IMG}"  alt="" border="0" />


_________________

Back to top
View user's profile Photo Gallery
Newbie


PostPosted: Sun Jul 29, 2007 2:56 pm Reply with quote

getting error:
"Parse error: syntax error, unexpected T_STRING, expecting ')'" after posting code in theme.php

Code:
// random image at top in header
$array = array('vf2.png', 'vf3.png', 'vf4.png');
$image = rand(0, count($array)-1);

    $cpgtpl->assign_vars(array(
    'CSS_FILE'     => ereg('MSIE', $_SERVER['HTTP_USER_AGENT']) ? 'ie' : 'style',

'RAND_IMG' 	   => $array[$image],

I there might be a ")" missing somewhere


Back to top
View user's profile Visit poster's website
Lead Developer


PostPosted: Mon Jul 30, 2007 12:31 am Reply with quote

Don't include $cpgtpl->assign_vars(array(
'CSS_FILE' => ereg('MSIE', $_SERVER['HTTP_USER_AGENT']) ? 'ie' : 'style',

as it's changed for df 9.1.2 just put in the stuff above and below it.


_________________

Back to top
View user's profile Photo Gallery
Newbie


PostPosted: Mon Jul 30, 2007 1:35 am Reply with quote

okay this is now what I have in theme.php

PHP:
// random image at top in header
$array = array('vf2.png', 'vf3.png', 'vf4.png);
$image = rand(0, count($array)-1);

'
RAND_IMG' => $array[$image],

I am now getting the error message:
Parse error: syntax error, unexpected T_STRING, expecting ')' on line 45

I have the below on line 45
PHP:
'RAND_IMG' 	   => $array[$image]


Back to top
View user's profile Visit poster's website
Lead Developer


PostPosted: Tue Jul 31, 2007 7:45 am Reply with quote

I've tested it and confirm it still works just fine. You're missing a single quote after vf4.png.
Make sure you create a yourtheme/images/random/ folder and put your images in there.
Make sure you assign the variable for RAND_IMG where all the other variables are being assigned.


_________________

Back to top
View user's profile Photo Gallery
Newbie


PostPosted: Tue Jul 31, 2007 11:24 am Reply with quote

Thanks again Devon! I found the key to getting this to work properly is proper code placement. It didnt work until I placed it correctly.


Back to top
View user's profile Visit poster's website
Lead Developer


PostPosted: Tue Jul 31, 2007 12:51 pm Reply with quote

I need to find a better way of explaining this. Obviously didn't too good of a job on this one. It's hard trying to explain where to place code. Surprised


_________________

Back to top
View user's profile Photo Gallery
Newbie


PostPosted: Tue Jul 31, 2007 2:43 pm Reply with quote

I'll post my results to help. This is the DF_AcidTechBlue theme.php file that has ThemeCP2 on it. Those looking will need to perform a manual search below to see where I placed the code.

PHP:
<?php
/*********************************************
CPG Dragonflyâ„¢ CMS
********************************************
Copyright © 2004 - 2005 by CPG-Nuke Dev Team
www.dragonflycms.com

Dragonfly is released under the terms and conditions
of the GNU GPL version 2 or any later version
**********************************************/
if (!defined('CPG_NUKE')) { exit; }
define('THEME_VERSION', '9.1.0.0');

$gfxcolor = '#C0C000';
$bgcolor1 = '#242424';
$bgcolor2 = '#4b4c4c';
$bgcolor3 = '#2C2C2C';
$bgcolor4 = '#ff3a3a';
$textcolor1 = '#ffffff';
$textcolor2 = '#000000';
$hr = 1; # 1 to have horizonal rule in comments instead of table bgcolor

function OpenTable() {
echo '<div class="table1">';
}
function
OpenTable2() {
echo '<div class="table2">';
}

function
CloseTable() {
echo '</div>';
}
function
CloseTable2() {
echo '</div>';
}

function
themeheader() {
global $slogan, $sitename, $banners, $mainindex, $adminindex, $cpgtpl, $site_logo, $db, $prefix, $userinfo, $CPG_SESS, $MAIN_CFG;
include('includes/cssmainmenu.php'); //comment this line to remove css menu
// random image at top in header
$array = array('vf2.png', 'vf3.png', 'vf4.png');
$image = rand(0, count($array)-1);
// BEGIN THEMECP MODULE QUERY //
$sql = "SELECT msg1, msg2, msg3, link1, link2, link3, link4, link5,
link6, link7, link8, link9, link10, link1url, link2url, link3url, link4url,
link5url, link6url, link7url, link8url, link9url, link10url, searchbox, flash FROM "
.$prefix."_themecp";
$result = $db->sql_query($sql);
list($msg1, $msg2, $msg3, $link1, $link2, $link3, $link4, $link5,
$link6, $link7, $link8, $link9, $link10, $link1url, $link2url, $link3url,
$link4url, $link5url, $link6url, $link7url, $link8url, $link9url, $link10url, $searchbox, $flash) = $db->sql_fetchrow($result);
// END THEMECP MODULE QUERY //
$imgr = $imgl = '';
// left blocks ?
if (blocks_visible('l')) {
$img = hideblock('600') ? 'plus.gif' : 'minus.gif';
$imgl = '<img alt="Toggle Content" title="Toggle Content"
id="pic600" src="themes/'
.$CPG_SESS['theme'].'/images/'.$img.'"
onclick="blockswitch(\'600\');" style="cursor:pointer; float:left; padding:2px 0 2px 0;" />'
;
}
// right blocks ?
if (blocks_visible('r')) {
$img = hideblock('601') ? 'plus.gif' : 'minus.gif';
$imgr = '<img alt="Toggle Content" title="Toggle Content"
id="pic601" src="themes/'
.$CPG_SESS['theme'].'/images/'.$img.'"
onclick="blockswitch(\'601\');" style="cursor:pointer; float:right; padding:2px 0 2px 0;" />'
;
}
$indexbodyrollover = '#3e60a8';
$viewforumrollover = '#3e60a8';
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$cpgtpl->assign_vars(array(
'CSS_IE' => ereg('MSIE 7.0', $user_agent) ? '<link rel="stylesheet" type="text/css" href="themes/'.$CPG_SESS['theme'].'
/style/ie7.css" />'
:
(
ereg('MSIE ([0-6].[0-9]{1,2})', $user_agent) ?
'<link rel="stylesheet" type="text/css" href="themes/'.$CPG_SESS['theme'].'/style/ie6.css" />' : ''),
'PUBLIC_HEADER' => !defined('ADMIN_PAGES'),
'RAND_IMG' => $array[$image],
'B_L_VISIBLE' => hideblock('600') ? 'style="display: none"' : '',
'B_L_HIDDEN' => hideblock('600') ? '' : 'style="display: none"',
'G_LEFTIMAGE' => $imgl,
'G_RIGHTIMAGE' => $imgr,
'S_IS_ADMIN' => is_admin(),
'S_CAN_ADMIN' => can_admin(),
'S_IS_USER' => is_user(),
'S_LOGO' => $site_logo,
'S_SITENAME' => $sitename,
'S_HOME' => _HOME,
'S_DOWNLOADS' => is_active('Downloads') ? _DownloadsLANG : false,
'S_FORUMS' => _ForumsLANG,
'S_MY_ACCOUNT' => is_user() ? _Your_AccountLANG : _BREG,
'S_ADMIN' => _ADMINISTRATION,
'S_BANNER' => ($banners) ? viewbanner() : '',
'S_MAIN_MENU' => isset($mmcontent) ? $mmcontent : false,
'U_MAININDEX' => $mainindex,
'U_DOWNLOADS' => getlink('Downloads'),
'U_FORUMS' => getlink('Forums'),
'U_MY_ACCOUNT' => getlink(is_user() ? 'Your_Account' :
'Your_Account&amp;file=register'),
'U_ADMININDEX' => $adminindex,
'T_MSG1' => $msg1,
'T_MSG2' => $msg2,
'T_MSG3' => $msg3,
'T_LINK1' => $link1,
'T_LINK2' => $link2,
'T_LINK3' => $link3,
'T_LINK4' => $link4,
'T_LINK5' => $link5,
'T_LINK6' => $link6,
'T_LINK7' => $link7,
'T_LINK8' => $link8,
'T_LINK9' => $link9,
'T_LINK10' => $link10,
'T_LINK1URL' => $link1url,
'T_LINK2URL' => $link2url,
'T_LINK3URL' => $link3url,
'T_LINK4URL' => $link4url,
'T_LINK5URL' => $link5url,
'T_LINK6URL' => $link6url,
'T_LINK7URL' => $link7url,
'T_LINK8URL' => $link8url,
'T_LINK9URL' => $link9url,
'T_LINK10URL' => $link10url,
'T_FLASH' => $flash,
'T_SEARCHBOX' => $searchbox,
'T_INDEXBODYROLLOVER' => $indexbodyrollover,
'T_VIEWFORUMROLLOVER' => $viewforumrollover,
));
blocks('left');
}

function
themefooter() {
global $showblocks, $banners, $cpgtpl, $foot1, $foot2, $foot3, $copyright, $db;
blocks('right');
$cpgtpl->assign_vars(array(
'B_R_VISIBLE' => hideblock('601') ? 'style="display: none"' : '',
'B_R_HIDDEN' => hideblock('601') ? '' : 'style="display: none"',
'S_FOOTER' => footmsg()
));
$cpgtpl->set_filenames(array('footer' => 'footer.html'));
$cpgtpl->display('footer');
}

/***********************************************************************************

void themesidebox

Output the specific block to left or right
$title : the title of the block
$content: all formatted content for the block
$bid : the database record ID of the block

************************************************************************************/
function
themesidebox($title, $content, $bid=0) {
global $cpgtpl, $themeblockside, $CPG_SESS;
$cpgtpl->assign_block_vars($themeblockside.'block', array(
'S_TITLE' => $title,
'S_CONTENT' => $content,
'S_BID' => $bid,
'S_VISIBLE' => hideblock($bid) ? 'style="display:none"' : '',
'S_HIDDEN' => hideblock($bid) ? '' : 'style="display:none"',
'S_IMAGE' => 'themes/'.$CPG_SESS['theme'].'/images/'.(hideblock($bid) ? 'plus.gif' : 'minus.gif')
));
if ($themeblockside == '') {
$cpgtpl->set_filenames(array('block' => 'block.html'));
$cpgtpl->display('block');
}
}
/***********************************************************************************

string theme_open_form

Creates start tag for form
$get_link : link for action default blank
$form_name : useful for styling and nbbcode
$legend: optional string value is used in form lagend tag
$border: optional use 1 to not show border on fieldset from stylesheet
************************************************************************************/
function
theme_open_form($link, $form_name=false, $legend=false,$tborder=false) {
$leg = $legend ? "<legend>$legend</legend>" : '';
$bord = $tborder ? $tborder : '';
$form_name = $form_name ? ' name="'.$form_name.'" id="'.$form_name.'"' :'';
return '<fieldset '.$bord.'>'.$leg.'<form method="post" action="'.$link.'"'.$form_name.'
enctype="multipart/form-data" accept-charset="utf-8">'
;
}
function
theme_close_form() {
return '</form></fieldset>';
}
/***********************************************************************************

string theme_yesno_option

Creates 2 radio buttons with a Yes and No option
$name : name for the <input>
$value: current value, 1 = yes, 0 = no

************************************************************************************/
function
theme_yesno_option($name, $value=0) {
$sel[(!$value)] = '';
$sel[$value] = ' selected="selected"';
$select = '<select class="set" name="'.$name.'" id="'.$name."\">\n";
$select .= '<option value="1"'.$sel[1].">"._YES."</option>\n";
$select .= '<option value="0"'.$sel[0].">"._NO."</option>\n";
return $select.'</select>';
}
/***********************************************************************************

string theme_select_option

Creates a selection dropdown box of all given variables in the array
$name : name for the <select>
$value: current/default value
$array: array like array("value1","value2")

************************************************************************************/
function
theme_select_option($name, $value, $array) {
$sel[$value] = ' selected="selected"';
$select = '<select class="set" name="'.$name.'" id="'.$name."\">\n";
foreach($array as $var) {
$select .= '<option'.(isset($sel[$var])?$sel[$var]:'').">$var</option>\n";
}
return $select.'</select>';
}
/***********************************************************************************

string theme_select_box

Creates a selection dropdown box of all given variables in the multi array
$name : name for the <select>
$value: current/default value
$array: array like array("value1 => title1","value2 => title2")

************************************************************************************/
function
theme_select_box($name, $value, $array) {
$select = '<select class="set" name="'.$name.'" id="'.$name."\">\n";
foreach($array as $val => $title) {
$select .= "<option value=\"$val\"".(($val==$value) ? ' selected="selected"' : '').">$title</option>\n";
}
return $select.'</select>';
}




Back to top
View user's profile Visit poster's website
  Page 1 of 1All times are GMT - 5 Hours

Post new topic   Reply to topic    Forum Index » Tips & Tricks Printer Friendly Page

  
  
  
 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


RSS-News
RSS-Downloads
RSS-Forums
RSS-KnowledgeBase
Valid CSS!
Valid HTML 4.01!

Site Search | Support | Contact | Payments | Link to Us
All TCD logos and trademarks in this site are property of TreasureCoastDesigns.com
Interactive software released under GNU GPL, Code Credits, Privacy Policy
TCD_Natural © T.C.D.