PHP for Poets

PHP ElephantOK, here we are at the elephant in the room. I don’t know how many of my writer friends are still with me on this journey (especially the one who promised to bombard me with questions but has been ominously silent instead). We are about to start using PHP, and I want to be clear that we are not going to master it. We will use what we need without necessarily understanding the reasons for things. It’s not ideal, but it is better than not learning any at all because it is too intimidating. So buck up, it won’t bite, let’s go!

A Small Digression About HTML

The book (affiliate link)assumes that you are a web designer who already knows a fair amount about HTML. If your eyes are glazing over at this point, stop. Face the fear. It’s not your mother’s programming language here. It’s all based on TEXT, and you are a writer, dammit, you can handle writing text.Β  Do you know what the HTML command is for a title on a page? Guess what, it’s the word Title. In brackets. So stop kicking and screaming and take a look at this friendly link on HTML for Bloggers from a decidedly non-techy person. I’ll wait. Remember, Rome was not burned in a day.

Back to Jesse’s Helpful File

Remember Jesse gave us a sample file to work with? All being well, you pasted it into your index.php file, and when you looked at the site, it showed a rather ugly set of links and lots of Lorem ipsum. Click on the picture if you want to see it in a bigger format.

Jesse's file

The site with Jesse’s HTML

The document title (what shows at the top of the page) is currently “My Super Simple WordPress Theme”. That’s obviously not the title we want for our own page. So let’s look at the HTML document. The title code looks like this:

<title>My Super Simple WordPress Theme</title>

That’s another error in the book, by the way, in case you were wondering. It says that the title is “Jesse Friedman | Developer” but that is actually the first heading. We’ll get to that later.

If we were just doing HTML, we would change the text above to what we want it to be. But then every time we wanted to change the title we’d have to edit the page again, and more importantly, we’d have to do that for every page on our site. That’s an awful lot of editing, and who wants to do that? Ideally, we’d just put whatever we want to have in the title in the settings for the page, and WordPress would put it in the right place. That’s exactly what PHP is for. I’m going to tell you what PHP call to use, and you don’t have to understand the syntax to use it. Trust me.

Enter PHP

The PHP function we are going to use is called bloginfo(). Not surprisingly, its job is to get the information about yourΒ  blog that’s been entered in the Settings tab on the Dashboard, and put it wherever you called the function. The book has a whole list of parameters you can give bloginfo(), but right now we are just interested in the page title, a parameter called ‘name’.Β  Here is the call to put in instead of that bit of HTML:

<title><?php bloginfo(‘name’); ?></title>

OK, breathe. All you need to know here is that every PHP call has to start and end with <?php ?>. Just try editing the index.php file with the above (heck, just cut and paste!). Refresh or upload as you figured out in the last post (depending on whether you are working locally or remotely). Now, whatever you put in the settings should be showing at the top of Jesse’s page. Yes? Isn’t it fun? If it isn’t showing, let me know and we’ll try to figure it out. We’re in this adventure together, after all.

I’m going to stop here and let you digest and play for a bit. Remember that the information for bloginfo() comes from the Settings tab in your Dashboard. Have fun and be sure to share any questions or comments below.

2 thoughts on “PHP for Poets

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge

This site uses Akismet to reduce spam. Learn how your comment data is processed.