little-man

Parenthood – The journey begins

Parenthood:

Parenthood is a never-ending journey and every day is a new adventure into making mistakes while trying to keep some sanity. Parenthood has no rules, guidelines or even a reference guide but it is still a great thing to be a part of. I entered upon this journey on June 7. Okay not entirely but that was the day my little boy, Salvador, was born so I will count that as the actual day the journey began. I will add more and more pages as time goes on and I get time to share these little life lessons.

Parenthood and the rules

Really there have been no rules for either one of us since SJ was born. SJ because his middle name of course begins with a “J” and if you were to look at my little man you would say that is a big name for a little guy. Now I’m just getting a little off track. The things that both of us have learned are things that people often tell us. A good example is when people tell us that we won’t be getting any sleep. I’m used to not sleeping so that is not really new to me. My body has been so REM deprived over the last years that I am more than capable of functioning on three or four hours of sleep a day. The one thing that has changed about that is that the so-called sleep pattern is more random that ever.

Parenthood and the guidelines

Okay the basic guidelines are pretty simple when you get down to it: Don’t kill the baby. That is the basic guideline and the one thing to really follow. Everyday is an exploration into a world of how to. How to keep the little one entertained while keeping your sanity, how to keep him quiet long enough to make a bottle so he won’t scream your ears off. No one thing will work the same way the next day. That is one thing you can count on to be true. There are moments when you will want to be alone to think, read or do something so simple as taking a shower but it can feel like forever because you are changing, feeding, burping and then changing again just to keep your little one from bawling.

What can oftentimes make things easy is having somebody there to help out to accomplish those basic everyday tasks like doing laundry, eating, cooking, cleaning or taking a bath. Unfortunately, I know some people out there don’t often have that luxury and I often wonder about how they manage to do it and have a huge amount of respect for them for being able to pull it off.

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

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:

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:

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:

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.

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:

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.

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.

Vary all the vagrants

It’s no secret that creating a proper web hosting environment can be a pain. Main reason being that there are many things that you have to take into consideration. Processor, storage, memory and sometimes if the motherboard can support it all. And I’m getting far ahead of myself again.

When it comes to creating WordPress themes and plugins finding the right environment can be tricky. Even more so when you use a Windows operating system.

Vagrant

What is it? Vagrant is an amazing tool and an amazing thing to get to know. I’m still in the process of learning and I love it. It does deal a lot with the command line so I have to familiarize myself with that once more. It has been years since I’ve used it.

Virtual Box

Yes. A box. A virtual one at that. VirtualBox is another great tool when it comes to creating a working environment. The main reason I love it is because you can have several machines on one system. Meaning you can have Linux, Windows and possibly OSX running on any machine you want. Keep in mind it is a virtual instance and not the real thing so some errors may occur.

Learning as you go

A few weeks ago I saw more and more posts being shared about VVV. I was super impressed and fell in love with it. So I did a little more research and came across a few other posts about how to work with VVV. I figured I’d share with you a few of those:

Those are just some of the links I wanted to share. There are more but didn’t want to create a giant list of links. I mean after all that’s what a search engine is for, right?