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->ID);
echo "<a href='" . $url . "'>Click here and read our latest post!</a>";
Yeah, that’s it. Have a great day!
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:
$f_contents = file ("banners.txt");
$line = $f_contents[array_rand ($f_contents)];
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=”http://www.sponsor1.com”><img src=”banner1.gif”></a>
<a href=”http://www.sponsor222.com”><img src=”banner222.gif”></a>
<a href=”http://www.coolsite3.com”><img src=”coolestbanner.gif”></a>
Thats it! You can add how many lines of banners as you want in the textfile.