Translation

Lorong Panjang

PS: This is the Indonesian language translation for A List Apart’s article The Long Hallway by Jonathan Follett. Translated with the permission of A List Apart Magazine and the author[s].

3 Responses

WordPress

WordPress QuickTips: Getting a Post’s ID

In a project I’m working on, I need to find the ID of a Post (a Page, actually, but the truth is that this works for both) so that the theme does not display the sidebar on this particular Post, but still showing for the rest.

At first I’m looking at the Template Tag the_ID(). Unfortunately, this function automatically prints out the Post’s ID instead of returning the ID when called. In other words, the following is not possible:

// Check whether the Post's ID is 5.
// This does not work.
if(the_ID()==5) do something...

…because the_ID() does not return 5. It turns out, the working method is by using $post->ID:

// Check whether the Post's ID is 5.
// This works.
if($post->ID == 5 ) do something...

Also, in my experience, the $post variable is still available after The Loop is done, very useful in my quest of displaying/hiding sidebar depending on the Post’s ID:

// This works.
<div id="content">

  // The Loop
  <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
       // ...the usual content displaying stuff...
    <?php endwhile; ?>
  <?php endif; ?>
</div>

<?php
  // Outside The Loop!
  if($post->ID != 21) get_sidebar(); ?>

I suppose this works well on template files that only display 1 content (e.g: single.php, page.php). Expect crazy things to happen when calling $post outside The Loop inside template files that actually loops more than once (index.php, category.php, etc).

9 Responses

WordPress

Finding Query Count for a Certain Part in a WordPress Theme

Michael Castilla’s post on modifying individual posts in the loop got me to test the query count between the double loop and single loop with counter method. This is my way to count that query count.

Say the Magic Word

This is how you would display the (current) query count in your theme:

<?php echo get_num_queries(); ?>

This piece of code is usually found inside footer.php, right at the very end of the code to display the total queries needed to display that single page. The secret is that you can place it just about anywhere inside your theme, and it will obediently display the total of query so far.

Also, you can have more than one of these in one go, so you could place one before and one after a certain part of a theme:

<?php echo get_num_queries(); ?>

The Loop here...

<?php echo get_num_queries(); ?>

…and you will have the query count before the loop and after it. Subtract the number and there you go, you have the total of queries invoked for The Loop.

2 Responses

WordPress

Upgrading WordPress the “Sneaky” Way Part II: Finding Files Changed from Previous Version

Back in December 2007 I wrote a post explaining a method to upgrade your WordPress install by simply overwriting the changed files instead of reuploading everything. Back then I was assuming that the “new version available” post will always tell you what files are changed so it’s easy for you to know what to upload.

However, today 2.3.3 is out and the announcement does not mention anything about changed files. Darn.

Trac Browsing to the Rescue

So, I decided to look around WordPress’s Trac. Now, I don’t know much about Trac, so I’ll let Wikipedia explain:

Trac is an open source, web-based project management and bug-tracking tool[...] (Source)

Okay. So, in essence, this is the place where you go to find the WordPress source code in various versions, with notes on modifications and whatnot, from the earliest to the most updated. So it’s the right place to go.

And the nice thing is that it allows you to compare the difference between versions. Exactly what we needed.

First, go to the tags directory of the source. There you can see a list of every WordPress version, from 1.5 to 2.3.3 and everything in between. Choose the most updated version. In our case, 2.3.3.

If you do it right, this page will be opened. At the bottom of the page there’s the View Changes… button. Exactly what we need. Click it.

You will see a form like below:

Finding changed files using Trac

Except that in your case the input field might still be empty. Well, punch in the numbers the way I did: in the From field it’s “tags/x.x.x“, x.x.x is for the previous version, while in the To field it’s “tags/y.y.y” for the current version. Click View Changes. You don’t have to worry about the numbers on the two Revision input boxes.

And now you’ll see the list of files changed from previous version:

WordPress Trac's list of changed files

Those are the one you should upload and upgrade. Refer to the old tutorial for more detailed steps.

Now, if you’d excuse me, I have some upgrading to do.

Leave a response

WordPress

Prologue 140 Characters Limit Mod Update

Prologue gets updated, and here’s the list of new features/fixes:

  • The front page now shows a stream of recent updates instead of one update per user
  • Pages now have their own template and look much better
  • Avatars are only shown once for sequential posts by the same author (front page and tag pages)
  • Post titles are no longer empty, they are generated based on the beginning of each post
  • Works out of the box for WordPress.org 2.3.2

And so, I have updated the Twitter-like 140 chars limit mod as well.

Prologue Theme Mod with 140 Chars Limit

Download Prologue 140 Characters Limit Mod here.

3 Responses

Hello!

My name is Hafiz Rahman. I do standards-based web design and WordPress works. I'm open for new projects, and here's where you can contact me.