Adding a randomized script
-
I’m currently trying to add a randamized tip section to my wordpress sidebar. I’ve tried using a widget but it disposes of all the other info I have there already when I activate the widget, I’m told that most times there is some ‘default content’ coded in that disappears as soon as you put a widget into the sidebar.
So I tried a software solution. First I created a text file called tips.txt and added tips one per line e.g.
tip one
tip two
tip three and so onNext I created a tips.php file using the following
<?php $hash = floor(time() / (60*60*24)); srand($hash); $tips = array_map("trim", file("tips.txt")); $tip = $tips[array_rand($tips)]; echo $tip; ?>
And finally I added this line to my sidebar:
<?php require("tips.php"); ?>
and them ftp them via Dreamweaver.All the files are in the same directory ie the brandford directory
However, I get the following error messages:
Warning: file(tips.txt) [function.file]: failed to open stream: No such file or directory in /websites/LinuxPackage04/ba/bi/es/babies-worldwide.com/public_html/wp-content/themes/branford with mimbo sidebar/tips.php on line 6
Warning: array_map() [function.array-map]: Argument #2 should be an array in /websites/LinuxPackage04/ba/bi/es/babies-worldwide.com/public_html/wp-content/themes/branford with mimbo sidebar/tips.php on line 6
Warning: array_rand() [function.array-rand]: First argument has to be an array in /websites/LinuxPackage04/ba/bi/es/babies-worldwide.com/public_html/wp-content/themes/branford with mimbo sidebar/tips.php on line 8
Any idea what might be wrong, and more still how to fix it.
Kevin
- The topic ‘Adding a randomized script’ is closed to new replies.