The Science of Web Art, Design and Development

View posts for » Category "Server Side"

Domain redirect wizardry with .htaccess rules

So you decided your domain doesn’t fit you as well as you’d like. And you are also afraid you’ll be losing all the old links and search
engine ranking if you move to a new one. Maybe you also want to use the current domain for a different project that suits it best.

Or maybe you just want to change the structure of your URLs or you want a different URI structure in the new domain.

Let’s see how to write some htaccess rules so Apache can do the magic for you.

read full post…

Comments (23)

Tutorial: A category based archive on Wordpress

I followed Lorelle’s advice advice and added a category based archive on Zo’C’s archive page, and now I’m going to tell you how to create yours.

At the end of this post, you’ll find the complete code in a single piece.

Step 1: Create the template file and find the content area

The first thing to do is create a new template page for your theme. The easiest way to do it is by duplicating your default page template which is the file “page.php”. Login via FTP, SSH or your favorite method an copy that file to “category_archive.php” and start editing.

Edit your file so at the very beginning it has the following lines, they are responsible for telling Wordpress this is a template page and its name.

<?php
/*
Template Name: CategoryArchive
*/
?>

The reason why we copied the default page instead of starting from the scratch is that any theme has is peculiarities (footer, sidebar, header, this and that) and we want to preserve them all, we just want to change the content. So, now, you must find the content.

read full post…

Comments (70)

Django – A framework to easily build complex sites

If you haven’t heard about Django, it is a Python Based framework to build complex and resource savvy sites easily and quickly. I have been studying and playing with Django in the last days and I’m simply amazed about it.

If you are a designer rather than a developer, the word python might scare you a little, since you don’t want to learn any python at all. Instead, if you are a developer, you might be skeptic to read that complex sites can be built easily.

read full post…

Comments (5)

“Order By” in SQL queries and random selection of database items

Simple hint, how to select a number random items from a MySQL database:

SELECT *
FROM your_table
ORDER BY rand()
LIMIT 2;

The code above, selects all the fields from a database table named “your_table” orders the results randomically and gets the first two. Change two for your favourite number.

Recommended Reading

Want to see an example of this working? Just look to your right! On the sidebar, there is a section named “Recommended Reading”. This is a section with books I like and recommend. I keep a list of books on a database and I pick two six at random with a query like this, each time a page is loaded.

Maybe you did knew this command already, or at least you heard about the ORDER BY command, but do you exactly know how it works and how further you can go with it?

I’ll show you some nice things in this article.

read full post…

Comments (9)

Managing obsolete pages with one line of code

When I switched from Blogger to Wordpress I had to deal with the problem of how to deal with the old pages.

Blogger style of archiving was static. That means that for every post you created, the Blogger system created a static HTML page.

Wordpress on the other side creates pages dynamically, meaning that there is no .html file whatsoever, the page is created on the fly whenever you request it. A change in the database automatically reflects on the page.

Now, the problem is, the address of the new pages doesn’t match the address of the old ones.

read full post…

Comments (9)

How to build an events agenda with SQL

In my opinion, one of the coolest things of the site I’ve built to Paulo gazela is the event agenda on the navigation bar.

Of course there are many calendar programs around to add to your site and it’s also possible to integrate google calendar or a similar tool, but all Paulo needed was a way to show the events he was going to be in for the folowing, say, 15 days, and an easy interface to add them.

The solution is very simple. We’ve built a database with the date, time and details of the events and we created a SQL query to get all the events 15 days from the current date.

A single SQL query like the one below can handle everything


SELECT *
FROM event, place
WHERE event.place=place.id
  AND CURDATE() < = event.thedate
  AND DATE_ADD(CURDATE(),INTERVAL 15 DAY) >= event.thedate
ORDER BY
  event.thedate ASC,
  event.thetime ASC;

If you want to understand better what this is, to build the database tables and get some more detail, read on.

read full post…

Comments (0)