Adding category-specific post links to the sidebar.
(If you’re just tuning in, this is the fourth installment of my series of articles about using WordPress as a CMS to build an informational Web site. Throughout this series, I’m talking about a specific site I developed: Flying M Air, a helicopter tour and charter company I operate when I’m not writing and tweaking my Web sites.)
Before I begin this installment, I want to take a moment to remind readers that although the topics I’m covering in this series are for Intermediate to Advanced WordPress users, WordPress 2: Visual QuickStart Guide, which I co-authored with Miraz Jordan, is for Beginning to Intermediate users. The book uses an extremely structured step-by-step approach, with lots of referenced screenshots to guide readers through the completion of hundreds of tasks. (Click here to download a PDF file (2.3 MB) of part of Chapter 3.) This article series uses a more conversational narrative tone and assumes that readers already know the basics.
My point? Don’t shy away from the book if the articles in this series have been too difficult for you to follow. The book will likely provide you with the basic information you need to get started with WordPress and move on to the next step. After working with WordPress (and hopefully, the book) for a while, you’ll be ready to articles like the ones in this series.
One of the drawbacks of using a blog format for sharing information that isn’t necessarily date-specific is that entries are presented in reverse chronological order. To get around that, I had to tweak the dates of the posts so the ones I wanted to appear at the bottom of a category page would have earlier dates than the ones at the top.
The other related problem is that not everyone likes to scroll down a page to see all of its contents. So, for example, if I had six tours in my Wickenburg Tours category, there was a good chance that a site visitor would never scroll down the page to see them all.
To resolve this potential problem, I decided that I wanted a list of all tours to appear near the top of the sidebar. But only the tours for the category currently being viewed. So while viewing the Wickenburg Tours category, I wanted just the entries for that category’s tours to be listed.
To do this, I had to insert some conditional statements into the sidebar.php template file. Here’s an example:
<?php if ( is_category('2') ) : ?>
<li>
<h2>All Wickenburg Tours</h2>
<ul>
<?php
$posts = get_posts('numberposts=10&category=2&orderby=post_title&order=ASC');
foreach($posts as $post) :
?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; ?>
</ul>
</li>
<?php endif ; ?>
What this basically says is that if WordPress is displaying the Category 2 page, it should display a heading of “All Wickenburg Tours” followed by an unordered list of up to 10 post titles (with links) for category 2 in alphabetical order.
(Keep in mind that this code includes a lot of extra tags required by my theme for formatting lists in the sidebar; these tags must be stripped out or modified for other themes.)
I then created the same bit of code for each category that listed my tours and inserted it into the sidebar.php file, right after the search form.
I went a step further with this, however. I also wanted the appropriate list of posts to appear if a visitor was looking at a post on its own (single) page. So I copied and pasted all the conditional code to the area right above it, changed all the is_category tags in the copy to in_category tags, and inserted <?php if ( is_single() ) : ?> before the first conditional tag and <?php endif ; ?> after the last one. That set up the tags so they’d be executed properly on a single page, too.
The best way to see what I’m talking about is to just visit the site and experiment with its category and post links.
In the next installment of this series, I’ll explain how I got the images to automatically change in the left sidebar and on many of the pages.
Previous Entries in this Series:
WordPress, CMS, conditional, tags, howto
• Read 264 Times
Add to Del.icio.us •
Technorati This •
Digg This •
Stumble it! •
Twit This
Information from my WordPress Dashboard.
WordPress 2.0.4, the latest stable release in our Duke series, is available for immediate download. This release contains several important security fixes, so it’s highly recommended for all users. We’ve also rolled in a number of bug fixes (over 50!), so it’s a pretty solid release across the board.
Learn more on the WordPress.org site.
WordPress, update, bugfix
• Read 173 Times
Add to Del.icio.us •
Technorati This •
Digg This •
Stumble it! •
Twit This
Posted on July 29th, 2006 at 8:10 am · No Comments
Filed in:
Mac OS Books
Calling one playlist from another to keep the music fresh.
I listen to iTunes all day long when I’m working in my office. I’m sitting in front of the computer, it has 4,000 songs on it, and there are a pair of stereo speakers attached to it — why wouldn’t I use it to play music while I work?
I usually listen to it with the volume turned down very low. Classic rock and pop. Sometimes, when I need to concentrate — like when a topic I need to write about is complex and I’m having a hard time figuring out how to compose an explanation or instructions — I switch to new age or “smooth jazz.” Or turn it off completely. I can’t listen to podcasts while I work. (I can’t watch CNN and listen to the reporter while I’m reading that stupid ticker at the bottom of the screen, either. But I can chew gum and walk at the same time.)
Anyway, a long time ago, I created a smart playlist that lists 500 my most highly rated rock and pop songs. I’d listen to that while I worked.
If you’ve never created a smart playlist, it’s easy. Here’s how I created mine.
- In iTunes, choose File > New Smart Playlist (or, on a Mac, press Option-Command-N).
- In the Smart Playlist dialog that appears, use the pop-up menu and other controls on a line to set up matching criteria. For example, I wanted only rock songs, so I chose Genre from the first pop-up menu and is from the second pop-up menu. Then I entered Rock into the box.
- If desired, click the + button at the end of the line to add another line of matching criteria. In my example, I also wanted Pop songs, so I choose Genre and is and entered Pop. You can repeat this step as many times as you like to set up search criteria.

- If you have more than two lines of search criteria, choose an option from the pop-up menu at the top of the dialog. All matches all criteria. In my example, if I chose all, iTunes would look for songs that had a genre of Rock and Pop. That’s not possible — in fact you can’t use the all option if two or more lines of matching criteria have the same option chosen from the first pop-up menu. Any, which is what I used, tells iTunes to match any of the criteria — for example a genre of Rock or a genre of Pop. In general, all results in fewer matches than any.
- To limit the number of songs by other criteria, turn on the Limit to check box, choose an option from the first pop-up menu, and enter a value in the box. For example, you can limit to 500 songs, as I did, or 2 hours, or 3 gigabytes. Then choose an option from the second pop-up menu to indicate how iTunes should narrow down the list of included songs. I chose highest rated.
- If you only want iTunes to include checked songs, turn on the Match only checked songs check box.
- I recommend keeping Live Updating checked so that if you add any new songs, they’ll be considered for the playlist. To me, that’s the purpose of a smart playlist — it updates itself automatically.
- Click OK. The new playlist appears in the Source list with a box around its name. Use this opportunity to change the name to something that makes sense to you. I called mine High Rated Rock.
After a while, I realized that even though I had the random button clicked when I played this playlist, I seemed to be hearing the same songs all the time. At the same time, there were songs I hadn’t heard in weeks or months. Is random really random? I think not.
I decided to try creating a playlist that listed 100 of the least recently played songs from my High Rated Rock playlist. I’d then play that playlist, thus guaranteeing that all the music I was hearing while I worked was “fresh” — at least to me.
- In iTunes, choose File > New Smart Playlist (or, on a Mac, press Option-Command-N).
- Set up just one line of matching criteria that references the other playlist you want to draw from. For my example, I chose Playlist, is, High Rated Rock from the three pop-up menus.
- Turn on the Limit to check box and enter a value that’s smaller than the total number of songs in the playlist you referenced in the previous step. Then choose your matching criteria. I entered 100 and chose least recently played.

- If you only want iTunes to include checked songs, turn on the Match only checked songs check box. Note that you can include both checked and unchecked songs in one playlist and only checked songs in this playlist to further narrow down the selection.
- Turn on the live updating check box. This is important if you want the list to change each time a song has been played.
- Click OK. The new playlist appears in the Source list with a box around its name. Change the name to something that makes sense to you. I called mine Fresh Rock.
If you follow these instructions to duplicate my playlists (with your songs, of course), you’ll find that when you play the second playlist, each time a song ends, it disappears from the list and a new song is added. iTunes won’t play the songs in date order if you have the random button enabled while playing that playlist. Instead, it’ll randomly play the 100 least recently played, high rated songs in the genres you specified in the first playlist.
Playing a song from another playlist also modifies the list. Say, for example, that the Pink Floyd’s’ Learning to Fly is on your Fresh Rock playlist. But you’re not playing that playlist today. Today you’re playing all Pink Floyd songs. (Good choice; I do that a lot, too.) When Learning to Fly is finished playing, it disappears from the Fresh Rock playlist because it has been played recently. It just hasn’t been played in the Fresh Rock list.
As you can imagine, you can play around quite a bit with the smart playlist feature. I like it because it keeps me listening to my favorite songs — the ones I haven’t heard lately, that is — without having to touch iTunes’ controls during play.
[composed at the top of a mesa in the middle of nowhere with ecto]
iTunes, iPod, howto, playlists, mp3
• Read 748 Times
Add to Del.icio.us •
Technorati This •
Digg This •
Stumble it! •
Twit This
• Read 165 Times
Add to Del.icio.us •
Technorati This •
Digg This •
Stumble it! •
Twit This
Dr Dave sends out the alarm; I spread the word.
Dr Dave, developer of the must-have spam prevention tool, Spam Karma, sent out the following alert message to all Spam Karma users as an announcement in the Spam Karma administration panel:
MAJOR SECURITY ANNOUNCEMENT
Affecting all WP users (this is not specifically a Spam Karma problem). Please immediately disable ‘guest user registration’ on your blog if it’s enabled and advise all your friends to do so (details here). I cannot give too much technical details as it would further endanger vulnerable Wordpress users, but trust me this is not a joke.
What Dr Dave means is to follow these instructions:
- Log in to your WordPress blog and display the Dashboard.
- Click Options to display the General Options administration panel.
- Turn OFF the Anyone can register check box under Membership.

- Click the Update Options button at the bottom of the window.
On his site, Dr Dave also recommends that if this option had been turned on, you should view your Users list and delete any user you’re not sure about.
Dr Dave did not provide any details for this security problem. He’s worried that it’ll spread the word about how a WordPress system might be compromised.
Our advice: just do it. I’m sure more details (and probably a fix) will come soon.
WordPress, security, problem
• Read 203 Times
Add to Del.icio.us •
Technorati This •
Digg This •
Stumble it! •
Twit This
• Read 180 Times
Add to Del.icio.us •
Technorati This •
Digg This •
Stumble it! •
Twit This