Coding up a storm.
January 11th, 2010
I’ve been working on a new theme for this blog over the weekend. However, I still have a little trouble with the PHP, since I know next to nothing about it. I rely on cheat sheets (like this fabulous one from WP Candy) and tutorials. I use this one from WPDesigner.com, and even while it’s a little dated, it’s a good stepping stone for those unfamiliar with WordPress’ codex.
Anyhow, I’m really excited about this new theme. It’s really going to showcase my… internet geekdom. I will just leave it at that.
I am having a small problem though. I wanted to use a custom field to input an “emotion” into my author post line, like so:
Nichole wrote this with sheer awesome.
However, only newer posts will have this custom field entry. Old ones would look more like this, since there would be no entry for the custom field.
Nichole wrote this with.
See? Not good. I am figuring (and correct me if I’m wrong, especially if you are better versed in PHP than my sorry self) that I need an if/else statement. The code I currently have is as follows.
Any ideas on how to turn it into something that says, “If there is meta data to post, post it. If there isn’t, echo or print or post or whatever this default value of ‘love’.”
I really need to work on my programming.
Look forward to jinked.net’s version 2 layout some time this week!

Take this
ID, $key, true);
?>
And make it this
ID, $key, true) != “”) {
get_post_meta($post->ID, $key, true);
}
?>
Sorry I saw this earlier and thought you had figured it out or would have responded sooner. My bad on the misread.
.-= Richard Orelup´s last blog ..Social Media Survey for those in NW Indiana =-.
Just hit me after I sent that that it wasn’t complete.
Some place you are generating the
“Nichole wrote this with”
And that needs to be included inside the if. So make the above echo
WAIT, I just went to copy my above code and noticed that it was all messed up. One sec , BRB :)
.-= Richard Orelup´s last blog ..Social Media Survey for those in NW Indiana =-.
Okay third comment is the charm.
http://gist.github.com/274049
I put the code there so you can see it. The last one has the “Nichole wrote this with” part included in it because you need to have it inside the if because you don’t want it to show up at all unless it’s got something for the field.
I’m sure there’s a way to do it, Nichole. I’ll take a look a little later this morning, when I have some spare time…
I’m guessing that you’d just have to pull the get_post_meta function out of the echo and put it into a variable, then do your if statement. If your variable = “”, then variable == “love.” Then echo variable. Something like that.
.-= Rich Schmidt´s last blog ..It’s nice to know you’re making a difference =-.
Try something like this:
ID, $key, true);
if($something != “”) {
echo $something;
}
?>
;) Glad you’re getting some answers.
BTW, for getting code into my WP posts, I use the SyntaxHighlighter Evolved (http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/) plugin. Not sure if it will help you, but it will make other code look nice (and be selectable, copyable, printable…).
.-= Anne´s last blog ..Just a Thought =-.
Yay! Checking to see what the reply comment looks like!
.-= Anne´s last blog ..Just a Thought =-.
Is this a plugin? What depth have you set the nesting to?
.-= Anne´s last blog ..Just a Thought =-.
Nope, not a plugin. I found out how to do it through this article.
You can have it nest as far as you want. I just thought 3 to be a good number.
Ah, many thanks!
Oh, by the way, you want to download NetBeans for PHP coding. Helps a lot!
.-= Ben´s last blog ..Actors Who Actually Act: Ed Norton =-.