Web Development

Implementing The Real Ultimte Front Page

Previously, I briefly illustrated how using a home.php file can allow you to build a custom layout to your WordPress blog’s home page. However, I didn’t really document it well enough for the casual WP user to implement by himself. For the unknowing of my readers, here is a guide to using my (really Rudd-O’s) discovery on your site.

If you already understand the concepts behind this, skip to the download link.

Let’s take a look at Rudd-O’s code again. Try to figure out what it’s doing:

1: <?php $homepage = get_settings('siteurl')."/home/";
2: global $wp;
3: $wp_received_argument = false;
4: foreach ($wp->query_vars as $k=>$v) if ($v) $wp_received_argument = true;
5: if ($wp_received_argument) require(TEMPLATEPATH . "/index.php");
6: else { wp_redirect($homepage);
7: exit(); } ?>

Line 1 gets the address of the blog and adds what we would use to access a static page with a slug of ‘home’.

Line 2 brings in the $wp object, which allows us to figure out if there are any parameters in the URL that we need to work with.

Line 3 sets a simple boolean value of ‘false’ to a variable that we will use to determine if we have recieved any parameters.

Line 4 looks at the $wp object and asks it if there are any parameters. If it finds any, then we set $wp_received_argument to ‘true’, and we will use that in the next line.

Line 5 is where the magic happens. If we have parameters, like the page number variable, then we will load the regular index.php template which will show you the normal blog page. Otherwise, we will continue to line 6 and 7.

Line 6 will run if we don’t have any parameters, which means that we want to show our special home page. We will send a redirect to the browser telling it to go to our static page. Then we quit running this page, since there is nothing more to do anyway.

This is a relatively simple concept. Rudd-O mentioned in his original article that one should add a link to /[wp-root]/page/1 somewhere, like in the header along with the page links for example. What that will do is give WordPress the parameters we need to have the blog listing shown. If you need help adding this link, leave a comment below.

Here’s the fun part. My hacks to Rudd-O’s code will replace the redirection of the original code. All HTML and PHP content is placed within home.php. Now that we are including our content in a straight-out PHP file, and not going back to the database to retrieve a page (via the WP Loop), you can even add a real mini-loop to your front page! You can do whatever layout you want with home.php now. (See my home page, which has the mini-loop, a list of categories, and my Flickr photostream, for an example).

Now that we understand what Rudd-O’s code accomplishes, it’s up to you to use your imagination. Until recently, my email that came upon request included some basic instructions, which read something like this:

Attached is a well-commented version of home.php. Use it to set up your custom layout, but don’t upload it yet.

In order for this to look and function properly on your site, you will need to adapt it to your theme. You will have to make the portion of home.php before my table-based layout look like the code in index.php from the top of the file to just before the loop, and from just past the loop until the end of the template. Remember to close the else statement with a right curly bracket.

Also, you will need to add the /page/1 (or ?paged=1 if you aren’t using pretty permalinks) link to the page list in header.php, which should include code to dynamically change the highlighting of the Home and Blog links.

For those basically familiar with PHP, HTML and some of the simpler CSS concepts, adapting the sample home.php file I am providing should be somewhat easy. If you don’t have such keen skills, you can review the W3Schools’ tutorials on HTML and PHP for a bit of help. (Sorry folks, these days I can’t handle doing the editing for everyone, although I wish I could.)

If you are convinced that you want a home page with a custom layout for your WordPress blog, I have provided an older version of my layout, plus all of the associated logic basedon Rudd-O’s code. As noted above, you will have and want to do lots of tweaking with it to make it look good, so grab the download below, and hack away.

 Download sample home.php layout »

New Attacks: Regstration Spam

Recently, I’ve been observing a new form of spam on my blog. It is coming in the form of vague registrations, with email addresses including Russian domains and strange user IDs. For now, it’s not too bad, so I won’t take serious action. If things do heat up, I’ll look into ways to effectively block spammers from clogging up my users table.

Changes Are Good, But Somethings Don’t Change

My experimenting with my site(s) has brought thousands of changes to it (them). I’ve played with templates and themes, modules, and hundreds of other features and tweaks. But there is one thing I’ve learned (not the hard way, yet): Leave URLs alone. Search engines need URLs to work with your site. If they all suddenly change, they may be looking at nothing, or your site will get lost forever.

It’s very tempting to all of a sudden change your permalink structure, or suddenly switch to them. Unless you have absolutely no choice in the matter, either take ‘em or leave ‘em at the beginning. One change in the middle will disturb the SEO status’s equilibrium (that a new one), with potentially lethal effects on the site’s ranking. Jonathan agrees with me.

I haven’t documented this, but it may be something that you would want to keep in mind. Some things are better off “like old times,” and left undisturbed. Perhaps I will report on this again in the future and see if my theory has proven itself.

Best Traffic Booster: Content Is King

After looking through my stats in Google Analytics lately, I noticed a trend in my search engine referrals. Ever since my post about my experience with the Math A Regents, I received dozens of hits from Google and other search engines. In addition, various other posts (including my mention of the Windows XP Royale theme) have brought me reliable traffic, which indicates that they are what people are looking for.

Rule numero uno: Make lots of good content. People (and search engines) look for pages that have something useful to say and that say it well. If possible, use spell checking (or copy and paste the text into another app and spell-check it there) before publishing you articles. Google Hacks says that with the advent of spell checking from search engines, spelling is as important to your content as water is to you (I like that metaphor).

Another trick I’ve discovered is to write in a timely fashion. Timing is a key factor in getting traffic. If you write about skiing and snowboarding, late fall and winter is probably the best time. Similarly, the optimal timeframe for content on roller coasters or surfing is late spring and summer. For example, if I would have written about the Math A Regents exam in August, I don’t think I would have as many hits (also, people were using “January 2007″ in their search phrases, which brought them to the archive page of that timeframe, but this is a side effect). If you want to write about a particular topic, take a few moments and think about whether it’s relevant at that time. If the answer is yes, pour out your thoughts, otherwise, write it down and save it for later (just don’t forget about it).

Finally, I suggest using SEF-friendly URLs or pretty permalinks (or whatever they are called in your respective CMS), or paying attention to your URLs if you hand code your site. Although I don’t seem to notice any effect from using this tip, I am guessing that it helps a little bit. At the very least, it makes your URLs look nice to your visitors.

WordPress Secrets: The Real Ultimate Static Front Page

Quick Note: If you are looking for the source, find it here.

With WordPress, there have been so many attempts to make the best static front page. Most variations have included plugins that change the default behavior of the home page to display a pre-selected WordPress page. However, the Turbocharged blog showcases a new technique that uses a theme’s home.php template, and even allows you to add pure PHP code to it. Rudd-O’s solution Continue reading »

Need WordPress Themes

I’ve used the trusty Regulus theme for many months, and liked it (still do), but it’s time for a new theme. I peeked around, and found the Anaconda theme (very nice three-column layout, supports widgets and many other plugins right out of the box), but even that doesn’t satisfy my desire for a nice theme. I’m looking for a three column layout with either white text on a black or dark gray background, or black text in a white content area (meaning black on the sides of the content area). Anyone know of anything?

Conquered HTML / CSS Problems

A few minutes before I started writing this post, I found myself pondering at a little display issue over here at Educated (where I use Binary Moon’s Regulus theme). In the sidebar on your left, you should see a section called Links, with a few links to my other sites. Before it used to be displayed as a second column parallel to Categories, widening the sidebar more than I would have liked it to be. So I dug into the theme’s sidebar.php file and started commenting out lots of stuff (mostly <div> tags), saving and consantly refreshing my browser, seeing if it acheived the desired effect. I also spent a few mintes trying to get everything up to valid XHTML, which – I’m telling you now – is not easy work, unless you are an expert or something.

Anyways, I managed to figure out how the formatting in the sidebar works – a whole lot of stuff is contained within a giant <div>, with a specific CSS class, which gives you the proper fonts, font sizes, and positioning of the text in the sidebar. I don’t know whether Ben Gillbanks intended for his template to be overly complicated to work with, but I think I’ve mastered his monstrosity of a creation, from the pages navbar to the sidebar. Next task: figure out how to make my own WordPress theme.

My Views on AJAX

AJAX isn’t new, but I haven’t really gotten around to expressing my views on it. For those that aren’t in the geek circle, AJAX stands for Asynchronous Javascript and XML. It’s used to build whole web sites in some cases (Gmail and dozens of other Web 2.0 sites) or to add bits of instantly-accessible functionality (Quick reply in vBulletin or Quick Edit in Invision Power board, My Pages at PCWorld.com, for example). AJAX uses existing technologies and languages to help create enhanced user experiences.

I think that some AJAX sites are well designed, like my favorite, Gmail. It uses AJAX as the basic foundation for the whole thing, so it’s either AJAX or the standard HTML version. Other sites (or products in some cases) rely on AJAX for doing certain – albeit important, like editing records in a CRM system – tasks, but don’t use it as the actual page rendering mechanism. Using that system, the AJAX-based feature might not really work sometimes. I can’t really think of anything off-hand right now, but I remember it happening at least once.

So the next time you use a Web site or service that uses AJAX (whether you know it or not), think about how the site acts. Can you do certain things without leaving the page? Do certain features perform really quickly? Does the site have to load (with an obvious message saying it’s doing so) before you can use it? If so, it’s run on AJAX, and may (or may not) provide a better browsing experience.