Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm not sure whats wrong with this line. Have I place this incorrectly? How do I get it to recognize the $yourcat->slug;

 $cat = get_query_var('cat');
 $yourcat = get_category ($cat);
 $uri = $_SERVER['REQUEST_URI'];
 if (($uri == '/category/$yourcat->slug;') { 
share|improve this question
add comment

2 Answers

your syntax is wrong change the single quotation mark to a double quotation mark and remove the semicolom on this line:

if (($uri == '/category/$yourcat->slug;') { 

it should become:

if (($uri == "/category/$yourcat->slug") {
share|improve this answer
add comment

AND you can surround the variable with curly brackets

if (($uri == "/category/{$yourcat->slug}") {

when you use single quotes, php does not look in the string for variables to replace. when you use double quotes it does. But in some cases there can be confusion such as this case. So when you do object reference like this, it's best to use the curly braces to explicitly say this is a variable that should be replaced.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.