Another PHP question

Status
Not open for further replies.

abhorrent

New member
Feb 6, 2008
783
13
0
Illinois
This may be easy but I've been looking and can not figure it out.
I've had a bad couple of days, usually I can struggle through this stuff but just can't seem to find an answer to this.

I got the below from the wordpress codex...
Code:
<?php if (is_category('Category A')) { ?>
<p>This is the text to describe category A</p>
<?php } elseif (is_category('Category B')) { ?>
<p>This is the text to describe category B</p>
<?php } else { ?>
<p>To be left blank or removed</p>
<?php } ?>
Basically I want to continue to add to that but if I were to add another line like..
Code:
<?php if (is_category('Category A')) { ?>
<p>This is the text to describe category A</p>
<?php } elseif (is_category('Category B')) { ?>
<p>This is the text to describe category B</p>
[COLOR=LemonChiffon]<?php } elseif (is_category('Category C')) { ?>
<p>This is the text to describe category C</p>[/COLOR]
<?php } else { ?>
<p>To be left blank</p>
<?php } ?>
I get a t-string error. I know I can do it with category pages but I'd
rather add 10 or 15 lines to this then create 10 or 15 category pages.

I've tried it a million different ways and got a million different errors,
It shouldn't be that difficult but I guess for someone that doesn't know a whole lot about php...

Anyway, and assistance would be appreciated.
 


I don't know, I don't think it's that particular line, but when I add a third elseif I get an error. An unexpected end error or something. if I leave it all as is and just go with whats in the first set of code, it works. But if I try and add that Category C line, I get the error.

Gotta run at the moment but will try again and see if I fucked something up. It's probably just me doing something wrong.
 
Hmm, I wonder if it's something in one of my category names. When I use the ID it seems to work. when I use the names I get the error. I don't know but that will do. By catID is the only thing I thing I didn't try. I'll have to redo it all by number which will be a bitch but such as life.

Thanks for your input though! Got me to take another look.
Probably just a stupid noob mistake in the end though.
 
Nope, it works. Not sure what the hell I did before. I stared at that fucking code forever and didn't see anything that looked out of place but who knows. For the arguments I used the catID's so maybe that made the difference.

Thanks all!
 
What category names do you have? Perhaps there was a character in the category name that you weren't escaping?
 
What category names do you have? Perhaps there was a character in the category name that you weren't escaping?

I have few that had dashes and a few others that end in "!"
For future reference, how would I escape something that ends in a character like that?
 
Dashes and ! won't matter. I was thinking of single quotes mainly. Those need to be escaped with a "\".
 
Status
Not open for further replies.