Forum Moderators: coopster

Message Too Old, No Replies

Problem with a simple IF ELSE

T_String Error

         

adder

8:39 pm on Jun 9, 2011 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi,

This is really embarrassing. I cannot find a parse error in a short snippet of code. I'm sure it is pretty obvious. Once I add this to my WordPress header.php:

<?php
if (is_home() && $post==$posts[0] && !is_paged())
{ echo '<div class="description"><h1><?php bloginfo('description'); ?></h1></div>'; }
else
{ echo '<div class="description"><?php bloginfo('description'); ?></div>'; }
?>


I get a:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'

I've read through W3Schools and php.net but I don't see how I can fit another semicolon here.

Please help!

Demaestro

9:57 pm on Jun 9, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You have PHP tags nested within PHP tags.

You have this: (bolded for clarity)

<?php
if (is_home() && $post==$posts[0] && !is_paged())
{ echo '<div class="description"><h1><?php bloginfo('description'); ?></h1></div>'; }
else
{ echo '<div class="description"><?php bloginfo('description'); ?></div>'; }
?>


You want this:

<?php
if (is_home() && $post==$posts[0] && !is_paged())
{ echo '<div class="description"><h1>' . bloginfo('description') . '</h1></div>'; }
else
{ echo '<div class="description">' . bloginfo('description') . '</div>'; }
?>

Notice that what I have done here is escaped the string then concatenated the bloginfo('description') to it...

This:
echo '<div class="description">' . bloginfo('description') . '</div>';

is the same thing as this:
echo '<div class="description">';
echo bloginfo('description');
echo '</div>';

adder

10:28 pm on Jun 10, 2011 (gmt 0)

10+ Year Member Top Contributors Of The Month



Great, thank you for helping!

I didn't know nested PHPs were a problem.