Category Archives: Silenced tutorials

Simple php image rotator

I am going to make a simple php image rotator that can also be used as a banner rotator.
First, create a new file called “images.txt”.
In this file, write embed code for your images, one per line, like:


<img src="path/url to image" alt="" />
<img src="path/url to image" alt="" />

Or you can write link codes, just in case you want to link the images to a page, or use it like a banner rotator, again one per line, like so:


<a href="link"><img src="path/url to image" alt="" /></a>
<a href="link"><img src="path/url to image" alt="" /></a>

php code for .php file


<?php
//open function
function random_image() {
//seed the random number generator
//only for php versions under 4.2.0
//if the version on your server is over 4.2.0 u can ignore
//the next line of code
srand((float) microtime() * 10000000);
//set data file name/path and read it
$f=file_get_contents('images.txt');
//create an array with all the images we found
$input = explode("\n",$f);
//create an array of keys for the random entries
//the number has to be between 1 and the number of
//elements in the array
$rand_keys = array_rand($input, 2);
//show a random image
echo $input[$rand_keys[0]];
//close function
}
//call the function and print the images
random_image();
?>

Disable news in wp-admin

This is the fastest way to remove the news from the wordpress admin dashboard.

Open up your favorite ftp program and connect to your blog.

In the wp-admin folder find the file index.php, make a backup of this file just in case u mess it up and you have to restore it later.

Now open up index.php and around line 15 you should find the following:

add_action( 'admin_head', 'index_js' );

Just comment out that line with double slashes like this:

//add_action( 'admin_head', 'index_js' );

Save the file and you`re done!

I only did this to my blog because I wanted to clean it up a bit.

Keep in mind that if you disable the news you will not see the latest updates from “WordPress Development Blog”. This can be a bad thing.

However, if you want to keep the “WordPress Development Blog” news and only disable the “Other WordPress News” do the following:

In stead of commenting out the line like told above, look for this:

jQuery('#planetnews').load('index-extra.php?jax=planetnews');

It should be around line 10. Just remove it, save the file and you`re done.

I only did this on Version 2.3 so if your version is prior to this it might not work exactly like this but you got the idea. It might not be the best way to do it but it`s the simplest and fastest for me.

Enjoy!

Simple text based hit counter

First make a new file called stats.txt and one called stats.php

Give write permission on the .txt file (CHMOD 666 or 777 if you don`t see a growing count)

php code for .php file


<?php
//set data file name/path
$data='stats.txt';
//read content fom the .txt file
$show = file_get_contents($data);
//write new content to the .txt file
$new=file_put_contents($data,$show+1);
//show your hit counter
echo $show;
?>

This is faster thran fopen() and if the data file dose not exists the script creates it, if it can.