My 500 and counting

The beginning of the year I promised myself that I would try to review 500 themes by the end of the year. I finally managed to reach that point and was super ecstatic about it that I just had to tweet about it:

Yes, a tweet. Just one tweet. And I even went ahead and made another little challenge for myself for the next goal: 750. No timeframe for that just yet but I am happy I completed the 500 and am making some good traction for the next goal.

Since making that little challenge to myself a few things have changed. One of which is that I am now able to push themes live as well as others. Makes for reducing the queue a little easier and tolerable in my point of view. There are a few other things but I’ll leave that for another post and another time.

Making a Portable Object Template for your WordPress theme or plugin

Yes, a bit of a lengthy title but I feel will get the point across and it is after all what I’m wanting to share with you today.

A what now?

A .pot ( or a Portable Object Template ) file is what WordPress uses and many PHP programs use for translation purposes. There are three files used. According to icanlocalize.com the files are:

  • MO – Machine Object. The MO file includes the same contents as PO file. The two files differ in their format. While a PO file is a text file and is easy for humans to read, MO files compiled and are easy for computers to read. Your web server will use the MO file to display the translations.
  • PO – Portable Object. This is the file that you receive back from the translators. It’s a text file that includes the original texts and the translations.
  • POT – Portable Object Template. This is the file that you get when you extract texts from the application. Normally, you send this file to your translators.

The one we will worry about is the last one. The POT file. There are several ways to create this file but the one I’ve found most useful was the one Otto was awesome enough to post for theme reviewers. It is super simple and does need a little tinkering and getting over the fear of the command line.

Yes, the command line. You know that little program that uses only text. No, not a text editor. Would be cool but no. Depending on the platform you are using it will be called a terminal window, command prompt or even powershell. All of these will work for what we will be creating.

Steps and requirements

Sorry, did I not mention there would be some requirements? The basic requirement is the command line and having PHP installed. The next would be getting the needed files from the repository. If you aren’t developing themes using a development version of WordPress leave your address in the comments below, I will find you and I will hit you. Hard. Even a release candidate is worth your investment unless you like to break things and have people yelling at you.

The tools and files you will need are in one of two locations. The first being in the svn developer site. You will need some sort of SVN software in order to get it, of course. The other would be from my github repo I created and modified. Yes, I created it just for this reason.

So the steps are as follows:

  1. Get files
  2. Extract files to correct folder
  3. Open command line
  4. Do some magic – or Voodoo, your choice
  5. Do happy dance!

Getting the correct files

I mentioned and linked two places where to get the needed files. The github link is the one I will go over. Part of that reason is not everybody will be fully familiar with version control or comfortable enough to not break things. Once that is downloaded we can open the zipped folder and move on to the next step!

Extracting the files

This is super simple thing to do. Extract the files to the root of your WordPress folder. It should look something like the image.

WordPress folder
WordPress folder

Open the command line

Now, there are several tools that are available for this. For Windows user there are two that I will often switch between: command prompt and powershell. I like using powershell more. We then will change to the directory where we have our WordPress installation.

For the next step will be going over some code, so be prepared.

Doing the magic

So here is where the real magic will happen. Once we are in the folder of our installation we will once more change directories to the i18n folder where all translation files reside. From there we will run a quick line of code that will create our new POT file.

$ php makepot.php wp-theme /path/to/theme /path/to/languages/theme-slug.pot

The thing to keep in mind is the $ is just a placeholder for the current directory you are in. It may differ from machine to machine. Once we have run that it will create a new file ( theme-slug.pot ) with all translation-ready strings. So try not to forget to translate all text strings!

How it works

I know there are a few people wondering how this actually works. I know I was for bit. I’ll try my best to make it a little more understandable why you need to have certain things in your command line.

The first thing you need to know is what you are doing. When you state php you are to a degree saying, “I want to run PHP code and use this file.” The next three things are what you are going to pass that file.

  1. The first thing we passed is what type of project you are creating the pot file for. In our case it is a wp-theme. There are a few other you can decide from like wp-plugin, wp-admin, wp-core and a few more that I just won’t list.
  2. The second thing we passed is the location of where to look for the translation functions. If you read through the list of what functions it looks for you are in for a treat because that list you can add to Poedit. (I’ve slowly walked away from that but would still recommend for beginners.)
  3. The last thing is the output of the file. Both the location and the name ( be sure to include the extension as well ) are what we will be using.

Now, you can do this with your plugins as well. Just be sure that the folder you are creating the POT file to does exist otherwise you will get errors and it won’t create the file for you.

I stated earlier that it works with a few changes; it’s true. The reason being I know there are some people who don’t like to use a development version of WordPress. Why? I don’t know but I made a few tweaks for it to work the way it works. Okay, I only changed three things but it works for the time being. I say that only because I’ve tested it on/off since the original post. If you encounter any issues please be sure to let me know!

Celebration will begin

There we have a newly created POT file ready to be sent to a translator. So, yes, by all means do your happy dance. Not only did you get over the slight fear of the command line but you possibly learned something new along the way.

Notes

If you don’t specify a path of where your theme/plugin resides it will create an error and will not work!
If you don’t specify a path, just a name for the file it will create the file in the i18n folder.

Keeping count of reviews

I hate posting this but I have to do it; sort of a status check for myself. To see where I stand and where I can be better. We all do it. I choose to do it publicly.

I can’t recall when I said I wanted to have my review count to be at 500 by the end of the year but I did. What review count you ask? Theme review of course. Since the beginning of the year I wanted to allot more time to reviewing and helping release more themes.

I can’t help it, I like to help when I can. It hasn’t been easy for me only because of the way I try and balance work and everyday life at the moment. I get home from work and I just want to review more themes when I should be sleeping.

As of this writing the tally is around 330 themes that I’ve looked over and read just about every single line of code. There are some that I glance over but for the most part I read all the code and of course look for key things when it comes to new themes.

I’m glad I’m keeping a good pace so far and will try and post an update when I finally reach that 500 theme mark.

Organizing all the media

Yeah, media. I love it. Most people live it and some are just indifferent about it. Blah! Is what I say to them. The reason I say it is because I love entertainment. Surprised? Don’t be. I am super easily amused. Like super easy. Like two-year-old easily.

A little history

The last couple of months I was trying to think of a way to organize my media library. No, not my computer. That would require way too much effort on my part and I just don’t have the attention span for it. I mean for my WordPress site. One thing that I felt could be improved. At least the experience.

My current library is the default one. Why? Because I never got a chance to get to it. I’ve wanted to change the layout for some time and use a grid system to display all the items. Do keep in mind I mostly have photos and very little audio and little-to-no video. For the time being. I will change that down the road, of course.

So here is the current look:

Media Library core

Recently I came across an amazing plugin that helped me do what I would like to do. At least for the time being. It’s called media grid. Simple solution that will hopefully make its way to core. As I write this out I’m also testing the development version and tweaking, trying to figure out how to break things and where it may break. It’s fun. You should try it one day. As Ferris Bueller once said:

“It is so choice; if you have the means, I highly recommend picking one up.”

Yes. I do believe in the plugin that much. Enough to write about it. Running through the paces I do have to say I love how it works on a desktop environment. The ability to change from thumbnail to a larger image is nice and being able to batch delete is great. Next phase – I feel – will be being able to preview the other media. Do remember that ever since WordPress 3.6 video and audio support were added and there are several plugins that also add other formats to the mix.

For me, the ones that matter most are video, audio, and of course images. So with the plugin enabled it does look like:

media-grid It is a little edited since the version I’m using wasn’t playing nice with the screen but that gives you an idea of what to expect. Pretty cool, right? So go, download it, try it out and if you’re feeling up to it: review it!

Forget your incentive

For some time the Theme Review team was doing fairly good when it came to keeping the ticket count down. Part of that was because those that got more reviews done for the month would get rewarded.

A reward?

Why yes. A reward for reviewing themes. A lot. I figured why not? Sounds like a great idea. Gamify theme reviews. Might work. Let the winner(s) choose a theme so it can be featured.

Here is where I think most people went wrong. They could feature their own. Don’t get me wrong I would almost fall into that category.

My initial thought was that the chosen theme would be one that was reviewed that month. Clearly it wasn’t the case. Many chose their own. Repeatedly. Over. And over again. Month, after month, after month and, you get the idea.

The issue

The biggest issue I noticed was that most were rushing the reviews. I am by no means the greatest reviewer on the team but do feel like I know my way around most frameworks now. At least I should by now. I say this only because I don’t always assign myself for a review. What I often do is actually look over what most people write, respond and change in some themes.

There are some things that are always missed. I admit I miss a few things as well. I feel bad when that happens but I am human. I don’t expect to catch every single error that one theme has let alone five.

Yeah, you read that right: five. There are some that will review multiple themes at once. I can’t do it. Part of that reason is the code from one theme will be on my mind as I look over another. Or I will forget what tab I’m in and put the wrong required issue on the wrong theme. It can get messy.

More trouble brewing

Those who chose their own themes I feel hurt the community.

Let me elaborate on that. In order to do that I have to really break things down a bit. I have to ask a few questions:

  • What is feature worthy?
  • What sets it apart?
  • Who designed it?

So, what makes a theme feature worthy? I feel that the design as well as the code have a huge impact on that. I’ve seen a few themes that use frameworks and often feel bloated.

A good example would be option frameworks that are included in a few themes. Often times they include so many files for such a simple thing like the ability to change text color. I feel that we should make decisions not give options. If they want to change it then they should be able to but it shouldn’t be expected. Just like I don’t expect to walk in to a restaurant and have the server ask me what kind of cup I would like to use for my water.

What would set themes apart then, right? If they all just followed the earlier rule then it would all be conformity and bland. Very uninspiring. But here is the kicker: creativity. What really sets a featured theme apart is in the creative way it leverages WordPress.

Twenty Fourteen is a fairly good example of what I mean. From the navigation used to the templates that are included the theme stands out more than the others. Looking through the code you can see both the complexity and simplicity of it all. Basic core template tags pushed and manipulated to create a symphony of design and code.

Do keep in mind that several people had input in the release of the theme.

So, a group of people working on a single theme should be featured? No, that’s not what I mean. To a certain extent there really is more than one person working on a theme. The developer/designer and the theme reviewer. Both are working together to get that theme approved and out to the world.

So what’s the beef?

The last month has brought on a few changes. The program has been put on hold until a decision has been made. Some people are upset, some are happy and I’m just thinking of a better way to review themes so that not only reviewers benefit but everybody does as well. I mean what good is contributing if it only benefits oneself? It would be like tickling a bear. Sure you can get him to laugh and you’ll laugh but in the end he will bite your head off. Okay, maybe not the greatest example but you get the idea.

I think what I find most troubling is that now that the program has been suspended many have stopped reviewing themes. Did we really need an incentive? Yes and no. Honestly is a little hard to justify either one I guess. I never really needed one; partially true.

My incentive: being a part of something bigger than myself.

Making a few commits

Let me give you a little bit of a back story first.

2 years ago

I began posting on the WordPress.org forums to help people out. I would only post on things that I knew for sure I knew the answers to or would help out. It felt like it at the time. Who knows really. It was, after all, two years ago. Not only that I would only really post at most twice a week. It was fine only because I didn’t have a goal in mind.

Yes and no. I had a goal in mind: to help; to share my knowledge. A lot has changed since then of course. Now, I have a slightly different goal in mind: make a career out of helping people. Yes, it may sound a little cheesy but it is true. A lot of it does stem from working at Starbucks. Many of the ‘regulars’ know that I won’t lie to them and will try my hardest to find something they will like. Now, I’m getting a little sidetracked.

Push forward

Over those last two years I kept mentioning a theme I was working on. Funny thing is I did and I didn’t. Part of that reason was I kept putting it aside. I would do a theme review, post a solution to the forums or see how I could help out somebody in the IRC channels. You know what? I loved every encounter and every sentence I wrote and read. So really it’s hard to be upset. I learned a lot from it all. Not just WordPress but programming in general.

Yes, I did also pick up a few other things along the way like the basics of SVN and Git and how to create a simple repository with those tools.

It’s safe to say the last two years I have been fairly busy. I have reviewed more themes, posted more often on the forums, make an attempt to post on IRC more frequently and have the honor of being one of  the Theme Review Team reps. It’s been an awesome year for me so far.

Say what?

Up until recently I never really said much about my theme. Yeah, I posted one or two photos of what it might look like but never any code. Okay maybe some code but never really said it was.

I began my theme with one thing in mind: simplicity. It sounds overly repetitive since a lot of themes claim the same thing. You know what? That’s fine. Over time I realized one thing: I don’t want complete simplicity. It would be nice to have but I don’t think I would achieve it without deleting the entire project. I mean how much simpler can you get with no code?

So, here goes, what I have been working on/off for the last year or so: Solea

Yeah, it’s not finished. There are a few things missing here and there but you know what? It can be expanded upon.

Child theme friendly post-formats

It’s no surprise I will always preach the making of child themes. Part of the reason is because you can make modifications without losing all that when it comes time to update the parent theme. I mean nothing more exciting than having to recall what files you changed, what code you added, deleted to brighten your day. Troubleshooting. It’s amazing.

The dilemma

Currently the biggest issue I’ve really seen is post formats. It’s not really easy to add to the parent theme. I mean yes and no. Adding to the list is not entirely possible without some parent theme editing and that is what I actually did. I created a quick function that checks and adds to the list of post formats.

The code

function get_theme_post_formats(){
    // $core_formats = array( 'link', 'chat', 'quote', 'gallery', 'status', 'image', 'aside', 'audio', 'video' );
    // base support for the theme
    $formats = array();
    // child if it wants to add
    $child_formats = apply_filters( 'theme_post_formats', array() );
    foreach( $child_formats as $key => $format ){
        if( ! array_key_exists( $format, $formats ) ){
            $formats["$key"] = $format;
        }
    }
    return $formats;
}
add_theme_support( 'post-formats', get_theme_post_formats() );

How it actually works is pretty nifty. What those fourteen little lines of code does is create a filter for child themes to use. That filter is: theme_post_formats. What you would do in the child theme’s function file is something like:

add_filter( 'theme_post_formats', 'child_formats' );
function child_formats(){
    return array( 'link', 'status', 'gallery' );
}

What that will do is add to the list of post formats of the parent theme. The way WordPress core makes you do it is by re-declaring the formats. What I mean by that is you have to call the function add_theme_support and list the already supported formats and add. Seems like a little too much work for some. At least how I feel about it; some may or may not agree with that.

To show you what I mean:

// Parent theme declaration
add_theme_support( 'post-formats', array( 'link', 'gallery', 'quote' );

// Child theme declaration
add_theme_support( 'post-formats', array( 'link', 'gallery', 'quote', 'status', 'chat' );

As you can see both can work. What it boils down to is how you want people to extend to your theme.

Getting the image count in WordPress

A long time ago I had a bit of an issue on how to get the image count from a post. At the time there wasn’t a way that I could think of to properly getting all the needed information; but then again I didn’t know as much as I do now.

I wanted to revisit this because I know it will help out at least one person if not more.

Since the last time I brought up the topic of multiple galleries in one post a lot has changed and a few new functions were added to help solve the dilemma. The key one that helped is: get_post_galleries

It was a simple idea but for some reason at the time it kept only giving my brain a beating. The reason was because it wouldn’t give the correct image count.

New solution

Up until now I was a little confused how I would solve my issue. I knew I needed to get all the galleries and then I needed to get all the images in those galleries. So, here is what I did:

// Get all the galleries in the current post
$galleries = get_post_galleries( get_the_ID(), false );
// Count all the galleries
$total_gal = count( $galleries );
/**
 * count all the images
 * @param array $array The array needed
 * @return int returns the number of images in the post
 */
function _get_total_images( $array ){
    $key = 0;
    $src = 0;
    while ( $key < count( $array ) ){
        $src += count( $array[$key]['src'] );
        $key++;
    }
    return intval( $src );
}

echo _get_total_images( $galleries );

As you can see it really isn’t much code. Part of that reason I wanted to keep the code as simple as possible. Feel free to extend it. In fact, I encourage you to do it.

How it works

What’s nice about the way I went about it is that it will require at least WordPress 3.6 and higher or else you will get an error. Nobody wants those, right?

The first thing we did was create a holder for all the galleries with the get_post_galleries function. We then count how many galleries there are and store that in another variable. That way we can use that later on to output the number if we want. Some people like that sort of thing.

Line 10 is where it goes a little different. I know you’re wondering why I’m declaring a function and then echoing that function in the last line. Part of that reason is because I wanted the ability for child themes to easily filter the text that I would use. Yes, I am aware I didn’t include any text strings. I’m pretty sure you can guess what it would say though, right?

Now, with that little tidbit in your arsenal go and read some code from the includes folder. You won’t be let down.

Using a post as a menu item

Truly a neat little find for many people. I know when I saw this for the first I was beyond astounded.

It does seem a little odd to use one but there are some random cases when it can be useful. Rather than having to use a page you can use a post. Granted it will show up with all the other posts but it is a cool thing to know.

There are a few steps required:

  1. Create the post.
  2. Create a menu
  3. Create the menu item

The first thing is, of course, to create the post. Could be anything you want about whatever you want. A cat, a dog or even a random turtle you saw the other day.

Next, you want to create a menu. In order to do so you want to go to the Appearance section and select Menus. That will bring up the Menus screen. If you don’t already have a menu created, name it whatever you want and press the create button.

Finally, we create the menu item. This is where it can be a little tricky. Why, you ask? Well, by default WordPress shows three options. You can actually have more. You just have to look in the right place.

screen-options

When you click on the Screen Options tab you get a nice little selection of things that you can now edit. As you can see from the following image you now can choose tags, categories and even posts as menu items.

new-options
Options galore!

From there you will choose what you want. In our case we will check off all the options because we like to live dangerously and love options.

Now we see that have a few more things in our roster of options.

new-menu-options

From there we can now choose posts as menu items. Awesome, right?

You don’t know text

Okay, maybe you do but what I’m talking about is a different kind of text. I’m talking about text strings in PHP code.

Text strings

What are they? Why do they matter? Well, they matter in themes that you want to make public or share. Oh, and plugins as well, I guess. If you’re into that sort of thing.

Over the last few weeks I’ve come across a few themes that didn’t quite make every line of text translatable. It almost drove me mad. Seriously. I was about ready to just punch my monitor. Thankfully another song came on and I was back to my calm self.

Functions

Yep, they do exists within WordPress. It’s actually quite nice that they do. Here are some that can be found in the includes folder:

  • __( 'I am a text string', 'theme-domain' )
  • _e( 'I am echoed', 'theme-domain' )
  • _x( 'Form', 'Art related', 'theme-domain' )
  • _ex( 'Form', 'Filing related', 'theme-domain' )
  • _n( 'Single', 'Plural', 'Number', 'theme-domain' )
  • _nx( 'Single', 'Double', 'Number', 'theme-domain' )
  • esc_attr__( 'I am an attribute', 'theme-domain' )
  • esc_attr_e( 'I will be an echoed attribute', 'theme-domain' )
  • esc_attr_x( 'Link', 'hyperlink', 'theme-domain' )

There are a few more but those are some of the ones I feel would be used more often than the others. In particular the first two. Those are by far the easiest ones to really miss. At least those are the ones I seem to find not being used when they should be.

What qualifies as a string?

When it comes down to it: anything that is inside markup. If it is wrapped inside an HTML tag then odds are it is a text string. A great example of this would be a very common line used by many themes. The “posted on” phrase. Now, there are several ways of doing this but I feel there are very few that are correct when it comes to translation strings.

$phrase = 'Posted on %s by %s';
printf( $phrase, get_the_time( get_option( 'date_format' ) ), get_the_author();

As you can see from the example I’ve provided it is a simple phrase that can easily be translated. The only thing you really have to do now is wrap the actual phrase with a translation function like:

$phrase = __( 'Posted on %1$s by %2$s', 'text-domain' );
printf( $phrase, get_the_time( get_option( 'date_format' ) ), get_the_author();

Fairly simple, right? But what about when it comes to numbers? That is what _n() is for actually. It’s a neat little function to use. It compares numbers! Yes, numbers. I love those things.

Okay, not literally compare numbers but fairly close. What it does do is actually determine which version of string to use. Sort of a juggling function with a twist. Really cool to use when you want to compare a single use, plural or even more.

A good example would be using it in a shopping cart.

echo "<h4>Items in cart</h4>";

$count = _n( 'Only one so far', 'Two items', get_total_items(), 'text-domain' );
printf( '<div class="cart-total">Currently: %s</div>', $count );

Pretty neat, right? I think so.

There are a few more functions to make translating a theme, or plugin, better but I feel those are the ones I find a bit more useful.