Get it All
Together

Oh, the drudge-work of webdesign. The repetition.

If you’re like me, you got into PCs back in the day because you found ways to make repetitious tasks go away when you used them. But sometimes in web design, there seems no way to avoid drudge work.

Ah! But then again, there’s always something. Whilst creating the newest version of my production site, DragonFlyEye.Net, I got sick to death of creating links. This was particularly true because of the way the page is put together: it’s using “clean” URLs, so creating a link to an article requires putting together a bunch of variables to make them look like directories to the browser.

The solution I came up with was a global function that created my links for me. All I had to do was pass it the needed variables, which are always conveniently held in arrays, anyway. I took the extra step (because, in my case, it was easier) of having the link-writing function write the whole anchor, including the bracketed content between the anchor tags.

Another advantage of using a global function to complete this task is that your links always come out consistently. If you want your domain to always be mydomain.com instead of www.mydomain.com, you can be sure that this happens when only one function is responsible for creating links.

For those of you who are not familiar with what I mean by “global function,” I mean that when I create a website, there are a few included files you can almost guarantee: a database incude file, a configuration include file and a functions include file. The configuration file contains all the usernames and passwords required to access special features (such as the database) of the site along with information such as mail servers and such. The database file includes only those functions which query the database, and again, this is for the sake of consistency and making sure that any problem querying the database can be tracked down to one location.

The functions file includes a list of functions which I find helpful where ever I am in the site, so I don’t have to constantly be copying the same function to each of those pages.  In my case, those functions include one to draw the correct number and selection of navigation buttons at the top of each page, a function to dynamically fill in sidebar content and a function that calls my DuckSoup Technorati API.  Of course, there is also a function that creates links for me.

I hope that this little blurb helps someone think in terms of compartmentalizing their code as I have done and avoiding unnecessary repetition!  Happy coding!