Work in Progress

Posted on

This is a new theme I’ve been tinkering with. It started out as a responsive design sandbox, but I want to develop it into a polished WP theme and eventually publish it.

If you don’t know about responsive design, drag the window to change it’s size. Magic!

Chinese Character Count in PHP

Posted on

I just spent five hours banging my head against the wall trying to figure this out. In hopes that I can prevent someone else from suffering the same fate, I decided to share this.

Background & Issues:

Chinese characters are word symbols rather than letters. A word count is impossible because there are no spaces between words.

Instead you have to do a character count. Unfortunately using a substring (PHP: substr()) won’t work because Chinese characters are encoded in Unicode.

Keep in mind that the $content string is UTF-8 encoded. Each Chinese character is composed of multiple characters. A ten character long string is equal to only three UTF-8 Chinese characters.

$content = '有史以來最好的網站';
// In Unicode (UTF-8) this string equals '%E6%9C%89%E5%8F%B2%E4%BB%A5%E4%BE%86%E6%9C%80%E5%A5%BD%E7%9A%84%E7%B6%B2%E7%AB%99'

$excerpt = substr($content, 0, 10);
// substr() does not recognize Unicode characters, this results in broken characters at the end of the excerpt.

echo $excerpt;

The above snippet will output:

有史以�

(The black-diamond-question-mark symbol denotes a broken Unicode character.)

Continue reading

Custom Taxonomies with WPML + My First Contribution to the WordPress Codex

Posted on

This may be a rare case, but if you call the get_terms(); function to retrieve a custom taxonomy array, and you are using the WPML (WordPress Multilingual) plugin for language translation, there is an undocumented (see below) argument that you will need to use.

If, for example, your custom taxonomy, “Birds,” has a the following terms: hummingbird, sparrow, dove, crow, parrot, hawk. You can use WPML to add Spanish translations: colibrí, gorrión, paloma, cuervo, loro, halcón. To display a list of the birds taxonomy, you would call:

$terms = get_terms('birds');

$count = count($terms);
if ($count > 0) {
    $bird_list = '<ul class="birds-list">';
    foreach ($terms as $term) {
        $bird_list .= '<li>' . $term->name . '</li>';
    }
    $bird_list .= '</ul>';
    echo $bird_list;
}

/****************************************

Regardless of which language is selected, this snippet will display:
       
    colibrí
    crow
    cuervo
    dove
    gorrión
    halcón
    hawk
    hummingbird
    loro
    paloma
    parrot
    sparrow
*/

Continue reading

Twitter Embeds or Snarks with Frickin’ Laser Beams

Posted on

You may have noticed some blogs (TechCrunch, Mashable, etc.) are now embedding tweets directly into their posts. By embedding Twitter posts, rather than inserting screenshots or copying and pasting text, the links become clickable, the text becomes searchable and the user’s custom profile styles are added to the embed. Most importantly, it looks cool.

"Twitter Embeds or Snarks with Frickin' Laser Beams" How to embed tweets with Blackbird Pie. BONUS: Cringeworthy puns! http://joey.is/yx7vp
@joepahl
Joe Pahl

The feature is called Blackbird Pie. It was published by Twitter Media (@twittermedia on Twitter). They provide, “Knowledge and tools to help you use Twitter to transform TV, entertainment, sports and journalism.” Twitter Media has published a variety of Twitter guidelines, metrics tools and API resources. Their blog is a great source for new features and Twitter news.

Continue reading

The Long, Long Story of a Really, Really Short Uniform Resource Locator (URL)

Posted on

Before I get into anything else, I want to point out my awesome new top-level domain (TLD), [dot]is. It comes courtesy of the Republic of Iceland. I borrowed the idea from noted WordPress guru, John Ford. I imagine that [dot]ises (it’s fun to say ises) will be more widely used in the future. Registering the domain was fairly simple and I’m paying less than I would have expected.

After registering joepahl.is I looked at what else I could lockdown. There are a lot of [dot]is domains available. Just for grins I checked joey.is. Lo and behold is was available! I had been planning on creating a link shortener at a subdomain of joepahl.is, but this was even better.

Continue reading

Raising the Bar for Web Fonts

Posted on

It started out as an experiment. Being a front-end developer, I wanted my blog have a unique feel. I changed the typography, but the Twenty Ten theme already uses the two best Web-safe fonts: Helvetica and Georgia. Any change I made felt like a step backwards.

A few sites have started using font embedding via the @font-face property, but I hadn’t tried it yet. Typekit was my first stop. I set up a free account and perused their library.

There are a few decent options in Typekit, but the best fonts are reserved for paid users. I really like Museo and Museo Sans, but in my case I don’t think they’d work. Plus, I really dislike the fact that Typekit makes free users include a floating badge. It’s too obtrusive.

Continue reading

Optimizing Google AdSense

Posted on

When I implemented Google AdSense I noticed my pages loading slower. This was to be somewhat expected, but pages were stopping while each ad loaded. The sidebar was especially slow to appear.

I decided that the best solution would be to load the ads in the footer, but I was a little nervous about how best to achieve this. Luckily, I found a great tutorial on building an AdSense loader. I had to make a few tweaks to the jQuery, but it was a great starting point.

I explained in an earlier post how to display multiple AdSense ads in the loop using WP_Query properties. This builds on that functionality.

Continue reading

WordPress Tips: Post Count and Current Post

Posted on

Recently, I added Google AdSense to my site. I wanted to have an ad beneath the last post on each page, and another ad in the middle of pages with multiple posts. To do this I needed to figure out the total number of posts in the current loop. I had a hard time figuring out how to do this so I wanted to share what I learned.

The $post_count and $current_post properties of the WP_Query class provide the total number of posts in the query and the index of the current post respectively. By using these two values I was able to identify the middle post and the last post on every page.

Continue reading