Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPierre Smith
11,842 Pointssyntax error with php if statement...
I'm trying to get run an if statement against the page title so that my sidebar changes depending on the title of the page.
what am I doing wrong.
here's my code.
<?php if ( get_the_title() == 'Job Classes' ); ?>
<div class="col-xs-12 col-md-4">
<ul class="nav nav-pills nav-stacked">
<li role="presentation" class="active"><a href="#classes">Job Classes</a></li>
<li role="presentation"><a href="#aba">ABA</a></li>
</ul>
</div>
<?php else : ?>
<?php if ( dynamic_sidebar( 'archive' ) ); ?>
<?php endif; ?>
2 Answers
Pierre Smith
11,842 PointsI put a semi colon instead of a colon on line 1.
Ted Sumner
Courses Plus Student 17,967 Pointsyou have to enclose your if code and else code in {}
Pierre Smith
11,842 PointsThanks for the reply. But it ended up being because I have a semi colon instead of a colon on my line 1.
Ted Sumner
Courses Plus Student 17,967 PointsIt must be a Wordpress thing. I have not seen that syntax before.
Michael Hazani
1,043 PointsTed Sumner: not a Wordpress thing, it's pretty standard php syntax; you can define conditionals either with brackets or with colons and "endifs", "endwhiles" etc. Makes for less cumbersome integration with HTML, for one thing. http://php.net/manual/en/control-structures.alternative-syntax.php