Adding a Free Counter to Your Site or Blog

Keeping count of visitors.

Ever wonder how many visitors your site or blog attracts? While you may have access to site statistics software that tracks and reports site visitors and hits, you may not. Or you may prefer a simple, old-fashioned visitor counter that’ll make this information easily available to visitors.

I use the free visitor counter offered by SiteMeter on my wickenburg-az.com Web site. And, for illustrational purposes, I’ve just added the same kind of counter to the sidebar of the WordPress book support Web site site. (Let’s see if Miraz lets me keep it there.)

Here’s how you can add a counter like this to your site or blog.

  1. Sign up for a SiteMeter account. It’s pretty straightforward and easy to do, so I won’t provide step-by-step guidance. Go to www.sitemeter.com, click the appropriate link, and provide the required information. You’ll get an e-mail message from the SiteMeter webmaster with login information for future use. You’re already logged in.
  2. Click the Manager link near the top of the page on the SiteMeter site. Then click the HTML Link on the left side of the page. You’ll see a list of links for adding code to various sites and blogs.
  3. Click the link labeled “Adding Site Meter to a WordPress blog hosted on your server.” (If you have a WordPress.com blog, you can click the link for that. Then follow the instructions there. These instructions assume you’re setting this up on a sever-installed WordPress blog.)
  4. Scroll down in the page that appears and select the contents of the edit box that displays the code for the counter. Use your browser’s Copy command to copy the code to the clipboard.
  5. Now open the sidebar.php or footer.php file for your theme with your favorite text editor or WordPress’s built-in theme editor.
  6. Position the insertion point where you want the counter to appear.
  7. Use your text editor’s or browser’s Paste command to paste in the code you copied.
  8. Save the file.
  9. View any page of your blog that includes the sidebar or footer (whichever file you modified) to make sure the page isn’t messed up. You should see a counter similar to the one shown in the sidebar of this page.

A few things to keep in mind:

  • You can set options on the SiteMeter site for your account to modify the appearance of the counter. If you want more options, you can pay for a premium account that gives you more control over the appearance.
  • You can also set option on the SiteMeter site to prevent the counter from including your computer, based on its IP address, to restart the counter, or even to count by an increment other than 1 (which is cheating, of course).
  • You should always back up a theme file before editing it, just in case you mess up the editing and need to go back to the original.
  • You can put the code in any theme file for your site, but it’s best to use a file that is accessed by all pages. That’s why I suggest sidebar.php or footer.php.
  • Depending on the theme and the file you modify, you may have to add additional HTML formatting codes for the counter to appear correctly. For example, you may have to surround the counter code with <li> and </li> codes to display it in the sidebar properly. Experiment with coding until you get it just right.

Of course, you can learn more about editing theme files for your site in Chapter 6 of our book, WordPress 2: Visual QuickStart Guide.

SiteMeter offers reports for activity on its site. Wait until you have some statistics and then use your login information to check it out. I think it’s cool — but then again, I love stats.

Using Conditional Tags

The basics of using conditional tags in a WordPress theme.

One of the things I like about the Soft-White theme Miraz and I chose for the WordPress VQS companion Web site is that it’s simple. Unfortunately, that’s also one of the things I don’t like.

The theme has just a few template files. index.php does most of the work. The problem with that is that it displays information that might not be appropriate for all content.

For example, near the top of each post, there’s some right-aligned meta information for the post that includes the category, author name, and date. While that’s good and useful information for a post like this one, it isn’t necessary at all for the contents of a Page, such as the About the Book page. First of all, you can’t apply a category to a Page, so it would always use the default category, which we renamed to General Info (we both hate “Uncategorized” or “Unfiled”). Second, who cares who wrote it? It’s general information for the site. And the date — does it really matter? I don’t think so. So I didn’t want any of that information to appear on Pages.

Since there isn’t a separate template for Pages and I really didn’t feel like creating one, I just edited index.php to include conditional statements.

A conditional statement is one that asks a question and then displays content based on the answer. In my conditional statement, I asked whether WordPress was displaying a Page. If the answer was yes, it would display nothing. If the answer was no, it would display the post’s meta information.

Now there are at least two ways to code conditional statements. Unfortunately (for me) I can only seem to use one way. So that’s what I’ll tell you about here. You can find information about the other, more complex way on the Conditional Tags page of the WordPress Codex.

There are three lines of code I needed to insert in the index.php file.

First, insert <?php if (is_page()) { ?> where you want to ask the question, “Is WordPress displaying a Page?”

Next, insert <?php } else { ?> after the content you want to display on Pages only. In my case, it was right after the first bit of code because I didn’t want to display anything at all.

Finally, insert <?php } ?> where you want to end the conditional content. Everything after this displays on all types of pages WordPres creates, including Pages.

So the final code for the title and post meta part of the revised index.php file looks like this:

<h1 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title() ?></a> </h1>
<div class="entrymeta">
<strong><?php if (is_page()) { ?></strong>
<strong><?php } else { ?></strong>
<?php _e("Filed under:"); ?> <?php the_category(',') ?> by <?php the_author_posts_link() ?> on <?php the_time('F j, Y') ?><strong><?php } ?></strong><?php edit_post_link('Edit This', ' | ', ''); ?><br />
 </div>

Experiment with this in your template files to add some intelligence to your posts.

Oh, and if you’re not quite sure what I mean by a Page (with a capital letter), read up in our book. Creating and editing posts and Pages are covered in detail in Chapter 3.

WordPress, conditional tags, templates

On the Intelligence of Quotes

Maria Speaks Episode 27: On the Intelligence of Quotes.

This short podcast is a reading from a recent article I wrote on my book support site for Microsoft Word users. It explains the difference between smart and straight quotes and tells you how to work with them in Microsoft Word. You can read the transcript of this podcast and see the accompanying screenshots at www.aneclecticmind.com

Transcripts:

Curly or “smart” quotes are single and double quote marks that curve in toward what they surround. This blog, if viewed in the intended font, displays all quotes as smart quotes. Smart quotes are also often referred to as “typographers” quotes because they’re common in printed work like books, magazine articles, and other documents.

You may not realize it, but a smart quote character is actually a different character than its corresponding straight quote. Think about it: it has to be. After all, it looks different, doesn’t it? That means it has to be a different character.

These characters are easy to type on a Macintosh. For example, to get the “ character, type Option-[. to get the ’ character, type Shift-Option-]. (Although there must be some way to type these in on a Windows computer, I don’t know how to do it; perhaps a reader can use the Comments link to share the keystrokes?)

Special CharactersIn Word, you can also use the Special Characters pane of the Symbols dialog. Choose Insert > Symbol to display the dialog and click the Special Characters tab or button. Scroll down to find the character you want (they’re listed at the bottom of the list) and double-click the one you want to insert it. This is a rather cumbersome way to get the job done, but it does work.

AutoFormat as You TypeFortunately, Word offers a better, automated way. You can set an option in the AutoFormat as you Type pane of the AutoCorrect dialog that will automatically convert every straight quote you type to the corresponding smart quote. Choose Tools > AutoCorrect and click the AutoFormat as You Type tab or button in the dialog that appears. Then turn on the “Straight quotes” with “Smart quotes” check box. (As you can see, that’s the only feature I have enabled in this pane on my copy of Word; I don’t like Word messing with the formatting of what I type, as I discuss in “Three Ways Word Can Drive You Crazy[er] and What You Can Do About Them.”) Click OK to save your setting.

From that point on, every time you type a single or double quote, Word will convert it to a smart quote. If your computer isn’t very fast, you might actually be able to see the conversion happen. And, if you use Word’s Undo feature, you can undo the conversion to revert the character back to the regular quote you typed.

I should mention here that this feature is enabled by default, so if you never changed this setting and you want smart quotes, you don’t have to do a thing to get them.

Now suppose you have a document that was typed without smart quotes. Perhaps a passage of text copied from a Web site or a document someone wrote with a plain old text editor. You want to dress up the document for printing and smart quotes are important to you. Do you have to retype all those quotes to “educate” them? Heck no! Just use Find and Replace.

Find and ReplaceFirst double check to make sure that the “Straight quotes” to “Smart quotes” feature is enabled as discussed above. Then choose Edit > Replace to display the Find and Replace window. Type the same plain old double quote character in the Find What and Replace With boxes. Then click Replace All. Word will replace the dumb double quotes with the correct smart quotes and tell you how many it replaced. Click OK to dismiss the confirmation dialog. Then type the same plain old single quote character in the Find What and Replace with boxes and click Replace All. Word replaces all the dumb single quotes with smart single quotes. Click OK to dismiss the confirmation dialog and close the Find and Replace window.

If you do this a lot, you might consider writing a macro that does the job for you. But that’s beyond the scope of this article.

What if you have a document with smart quotes and you need to turn them into straight quotes? Easy enough. Follow the same process, but before you use the Find and Replace window, check to make sure that the “Straight quotes” to “Smart quotes” option is turned off. Find and Replace should dumb up the quotes.

Now that you know the tricks, there’s no reason why your Word documents shouldn’t have the smartest quotes around.

Microsoft, Word, smart quotes

WordPress QuickStart Almost Done

Due to ship to the printer this Friday.

WordPress 2 Visual QuickStart GuideMiraz Jordan and I have been putting the finishing touches on WordPress 2: Visual QuickStart Guide for Peachpit Press. The book is set to go to the printer this coming Friday and should be in stores by the end of the month.

You can order a copy in advance from Amazon.com, BN.com, or Peachpit Press. The book appears to be selling quite briskly at Amazon; it’s ranking is relatively high for such a limited-interest book that hasn’t even been published yet.

Miraz and I will be providing support for the book on a separate Web site — www.wpvqs.com — although you’ll also find support articles here and on Miraz’s site. As I write this, the support Web site is already set up. But it’s a mess because we’ve been using it as a testing ground for plugins, theme file modifications, and other topics covered in the book. One day soon, I’ll wipe the site clean and reinstall WordPress from scratch. We’ll then build up the support site with articles, links, and other features to help readers learn more about WordPress.

So if you’re a WordPress user — or want to be one — keep checking in to learn more about WordPress and our book.