Just Another Dang Blog

A tech blog on IT, web development, graphic designs, freelancing, making money online and seo.
Welcome to lopau.com - a digital playground, online portfolio and blog of Paulo Orquillo
  • Home
  • About
  • Portfolio
  • Hire me
  • Templates
« Philippines Joins Worldwide Celebration of Software Freedom Day
Google Chrome browser now available »
Sep 03
Wordpress parse error: syntax error on PHP 5.2.x

Here is a short Wordpress troubleshooting tutorial for theme tweaking.

A theme I’m working on runs fine and was tested on PHP 4.3.x locally in my machine, I tried testing on PHP 5.2.x and I immediately encountered syntax error on Wordpress. Traced the problem to be inside the Loop in Wordpress. Sharing it here for those having hard time making their themes work on their host.




If you are getting these PHP Token errors like the following:

Parse error: syntax error, unexpected T_ENDWHILE

Parse error: syntax error, unexpected T_ELSE

Parse error: syntax error, unexpected T_ENDIF

Solution: check your if/else or while scripts and modify them accordingly to confirm to Wordpress or your initial PHP tags.

Example script courtesy of undersigned.net, This code changes every other post to their own css tags. This runs fine and tested on PHP 4.3.x only

<?php if ( have_posts() ) : while ( have_posts() ) : the_post();

$loopcounter++; ?>

<div class=“post”>

<?php if ($loopcounter % 2 == 0) { ?>

<h1 class=“even”><?php the_title(); ?></h1>

<?php } else { ?>

<h1 class=“odd”><?php the_title(); ?></h1>

<? } ?>

<?php the_content(); ?>

</div>

<?php endwhile; ?>

You used the if/else normal php codes inside the Wordpress loop tag. Make a strict code by simply changing your if/else to Wordpress tags to make it work on PHP 5.2.x.

<?php if ( have_posts() ) : while ( have_posts() ) : the_post();

$loopcounter++; ?>

<div class=“post”>

<?php if ($loopcounter % 2 == 0) : ?>

<h1 class=“even”><?php the_title(); ?></h1>

<?php else : ?>

<h1 class=“odd”><?php the_title(); ?></h1>

<? endif; ?>

<?php the_content(); ?>

</div>

<?php endwhile; ?>

That’s it, issue fixed! It should be similar to other scripts using similar coding style and not just to Wordpress. Happy theme tweaking!


This entry was posted on Wednesday, September 3rd, 2008 at 9:19 am and is filed under Tutorials, Wordpress. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Wordpress parse error: syntax error on PHP 5.2.x”

  1. Wordpress parse error: syntax error on PHP 5.2.x Says:
    September 3rd, 2008 at 10:37 am

    [...] Read the rest here: Wordpress parse error: syntax error on PHP 5.2.x [...]

Leave a Reply

  • Recent Posts

    • Did your PR went up or down?
    • Internet Marketing the way to go
    • Happy New Year!
    • The Spirit of Times- Zietgeist 2008
    • Boosting up your Alexa Ranking
  • Recent Comments

    • lopau: You’re welcome Danny. Glad to have helped.
    • lopau: Exactly, things will get busier and competition will tougher, the earlier you adapt internet marketing skills...
    • Ken Acton: Hi, You are right. All the forcasts have been for continued expansion of the internet. The current climate...
    • lopau: Just used the software again. And it also works with laptops locked with fingerprint. :)
    • deskapahendri: Thank for alexa tips
    • Danny: Wow thank you! Finally someone who explained the problem in a easy to understand way. I owe you a favour -...
  • Add to Technorati Favorites
  • Categories

    • Adsense
    • Airsoft
    • apple
    • Blogs
    • Browsers
    • CSS
    • Firefox
    • Flex
    • Fonts
    • Free WP Templates
    • Freelance
    • Google
    • iPhone
    • IT
    • Online Scams
    • Others
    • PHP
    • Political
    • Projects
    • Security
    • SEO
    • Social Marketing
    • Tutorials
    • Web Resources
    • Wordpress
  • Archives

    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • September 2008
    • August 2008
    • July 2008
    • June 2008
  • Blogroll

    • AmongEd.Org
    • Copongcopong’s Notes from Walk the walk
    • Get Rich Talks
    • The Passionate Pilgrim’s Musings and Ramblings
    • Tinokla Scribbles and Doodles
  • Links

    • LS Blogs
    • Pampanga Province Websites
    • Top Blogs Philippines
SUBSCRIBE


Web Development & Design - Top Blogs Philippines


Just Another Dang Blog is proudly powered by WordPress
Entries (RSS) and Comments (RSS).
Valid XHTML 1.0 Transitional Valid CSS!