• Home
  • About
  • Portfolio
  • Hire me
  • Templates
blog.lopau.com

Just Another Dang Blog

A tech blog about web development, graphic designs, freelancing, cloud computing, mobile development, innovations and seo.
Welcome to lopau.com - a digital playground, online portfolio, web experiments and blog of Paulo Orquillo
« 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.

2 Responses 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 [...]

  2. johnny easpices safran Says:
    October 24th, 2011 at 3:33 am

    Hi,

    Thanks for this wordpress troubleshooting turorial, I haven’t encountered this issue yet but it might be useful for me in the future.

    Thanks!!

Leave a Reply

  • Popular Posts

    • Fixing power problems with your LG Flatron Monitor (LG1753S)
    • Finally passed my Force.com Certified Developer Exam
    • DIY: HP Laptop Power Adapter Repair
    • How to Setup PHP, MySQL and phpMyAdmin on Mac OS X Snow Leopard
    • Setup EC2 and FileZilla with PPK file on Mac OS X
    • Safari Bug on Lion: The application Safari canceled restart

    Recent Comments

    • Swati: I am planning to write dev 401 next month.Could you please send me the materials and dumps that you have.My...
    • Apex: Great tut,Thanks
    • matt: Never been a fan of Steve Jobs or Bill Gates as they do seem to steal other peoples ideas then use them as...
    • Ash: I encountered the same issue, I went to activity monitor, checked on windowed processes and force killed Safari,...
    • lasersoul: Hi Guys Similar problem with a LG W2452T near enough to effect the fix in the same way. 4 bulging...
    • Ione Bentler: Actually there is another alternative. Get a refund. That’s what I did. I was so pissed off that...
    • Recent Posts

      • R.I.P Steve Jobs, Stay Hungry Stay Foolish
      • Inkling by Wacom
      • Create a Web Service using SOAP
      • 3D Augmented Reality platform(QR+AR) for iPhone, iPad, Android, BB
      • Create rewrite rules for friendly url for WordPress plugin custom queries
    • Blogroll

      • Abiel Online
      • Abiel's Tech Blog
      • Copongcopong’s Notes from Walk the walk
      • Get Rich Talks
      • Javi’s Go Blog
      • The Passionate Pilgrim’s Musings and Ramblings
      • Tinokla’s Scribbles and Doodles
    • Links

      • LS Blogs
      • Pampanga Province Websites
      • Top Blogs Philippines
      • Travel and Gobble
    • Proudly Pinoy!
    • Add to Technorati Favorites
    • Web Development & Design - Top Blogs Philippines

    • Sponsored Ads

      Summer Savings! $7.49 .com
      Ensogo
    • Categories

      • Adsense
      • Airsoft
      • Android
      • apple
      • Blogs
      • Browsers
      • Cloud Computing
      • CSS
      • Desktop Publishing
      • Facebook
      • Firefox
      • Flex
      • Fonts
      • Free WP Templates
      • Freelance
      • Google
      • Hardware
      • HTML 5
      • iOS
      • Ipad
      • iPhone
      • IT
      • Javascript
      • microsoft
      • Mobile Development
      • Online Scams
      • Others
      • Personal
      • Personal Finance
      • Photography
      • Photoshop
      • PHP
      • Political
      • Projects
      • SalesForce
      • Security
      • SEO
      • Social Marketing
      • Travelling
      • Troubleshooting
      • Tutorials
      • WAMP
      • Web Resources
      • Wordpress
    • Tags

      Adsense among ed andriod apache apple blogging Blogs Cloud Computing CSS cuil development earn online enable gd library Firefox Fonts force.com Freelance godaddy Google google analytics government increase traffic internet fraud internet scams iPhone knol knowledge content Money mysql online purchase page rank pagerank PHP politics pr search engines SEO social media content social networks text browser themes web traffic western union Wordpress zend certification

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