Currently Browsing


If, for any given reason, you are not able to implement a MySQL counter, here is the easiest solution for creating a flat file online users counter. Create a file called online.php, make it writable (either CHMOD 755 or CHMOD 777, depending on your server requirements), and insert the following code where you want the [...]

There are quite a handful of different post thumbnail solutions out there, but it seems that I found a very simple and compatible one that uses the famous timthumb library. Add this code to your functions page, functions.php: function post_image() { global $post, $posts; $thumb = ”; $output = preg_match_all(‘/<img.+src=[\'"]([^\'"]+)[\'"].*>/i’, $post->post_content, $matches); $thumb = $matches [...]

One of the latest features I’ve added to my sports fishing portal was the nice date feature. Instead of showing PHP formatted date and time, I wanted to display time since the action took place, like “4 hours ago”, “2 days ago”, “1 minute ago” and so on. <?php function nicetime($date) { if(empty($date)) { return [...]

I’ve been working a lot these days to complete several big projects, and a handful of smaller ones. They’re all related to PHP and optimization. I’ve been thinking of a switch-based PHP preloading technique, which I’m trying to implement in a couple of projects. What I’m trying to do exactly is update my CMSs and [...]

Like I promised in a previous post, here is the code required to show latest 5 posts followed by 15 more, like on my homepage. You need to edit the index.php template and add 2 sub-loops separated by wp_reset_query(). Simple as that. Here is the entire index.php code (you should be able to pull the [...]

3 Quick PHP Tips

1. Use a redirect function in PHP without header/location stuff: function redirect($page,$time) { echo ‘<meta http-equiv="refresh" content="’.$time.’; url=’.$page.’" />’; } Now use: redirect(‘index.php’,3); in order to redirect to index.php after 3 seconds. 2. Generate 3 characters salt strings: // Salt Generator function generate_salt() { // Declare $salt $salt = ”; // And create it with [...]

First of all you need the Simplepie library. You only need the file included in the archive. My example extracts 5 items from a recipe blog: <div class="block"> <h2>Latest Culinary Recipes</h2> <div class="content"> <?php $feed = new SimplePie(‘’);?> <ul> <?php foreach ($feed->get_items(0, 5) as $item): ?> <li>&raquo; <a href="<?php print $item->get_permalink();?>"><?php print substr(($item->get_title()),0,23);?> [...]</a></li> [...]

I’m talking here about extracting latest posts to a different site. I’m also assuming that the databases are on the same server. So here is the script: <?php // connect to the database server mysql_select_db(‘forum’); // run The query $results = mysql_query("SELECT * FROM phpbb_topics ORDER BY topic_time DESC LIMIT 10"); if ($results) { while($rand [...]

It took me a while to try and rephrase the title, but to no avail. Using the image.php script from my last article, I will read database entries and replace all tags with clickable thumbnails. All you need to do is have a database entry with an tag. Read the database (I’m sure you know [...]

Ever since I discovered PHP I tried to simplify everything by splitting files into most used parts and using include() to add them, reading files from directories and generating galleries on the fly, or by using many tricks to make my developer life easier. Today, I’ll show you how to use PHP and GD library [...]

Page 1 of 41234