PHP code: Permalink/URL to the latest/newest post in WordPress.

Here’s a little useful sample to get a link to the newest(latest, freshest… you get the idea) post in WordPress.

Here is the tiny but useful bit of code:

$latest = get_posts(array('numberposts' => 1));
$url = get_permalink($latest[0]->ID);
echo "<a href='" . $url . "'>Click here and read our latest post!</a>";

Yeah, that’s it. Have a great day!

The Worlds Simplest Banner Rotator Script (?)

Do you want to have a small banner rotator-script? You want it up and running fast and you do not want to use databases for something as simple as a banner rotator-script? Here is a free script that will rotate your banners, you could not find any more simple banner rotator script than this:


srand ((double)microtime()*1000000);
$f_contents = file ("banners.txt");
$line = $f_contents[array_rand ($f_contents)];
print $line;

So what does it do? It does open the textfile “banners.txt” which should be placed in the same folder as the php-file.
It then takes one random line from the textfile and displays it at your website.

So inside the banners.txt-file you should have small bits of HTML. One banner on each line like this:

<a href=””><img src=”banner1.gif”></a>
<a href=””><img src=”banner222.gif”></a>
<a href=””><img src=”coolestbanner.gif”></a>

Thats it! You can add how many lines of banners as you want in the textfile.