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

    • Fixing power problems with your LG Flatron Monitor (LG1753S)
    • Force Update your HTC Hero (GSM)
    • App Inventor for Andriod
    • Object Relationships and Fields
    • Force.com Custom Objects
  • Recent Comments

    • world.nse2rich: thanks pal i faced Same problem today this post was life saver And I solved it by settings uploads...
    • ForcePrepare: A new site on SalesForce Developer certification has been recently launched –...
    • htc hero: Does anybody know which kind of video recordsdata are supported? I remember the Intuition solely might dl...
    • lopau: its really a matter of preference and OS of choice. Andriod or IOs 4.0. Because of the competition they bring...
    • Benjamin Hall: anyone who makes money on the internet would love to know the secret of John Chow’s...
    • Sony BDPS370: Having spent loads of time reading many of the great blog posts about some of the HTC phones, this one...
  • Proudly Pinoy!
  • Add to Technorati Favorites
  • Web Development & Design - Top Blogs Philippines

  • Categories

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

    • July 2010
    • May 2010
    • April 2010
    • March 2010
    • February 2010
    • December 2009
    • November 2009
    • October 2009
    • September 2009
    • August 2009
    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • September 2008
    • August 2008
    • July 2008
    • June 2008
  • 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
  • Tags

    Adsense among ed andriod apache apple blogging Blogs Cloud Computing CSS cuil development earn online enable gd library Firefox Fonts Freelance Google google analytics government increase traffic internet fraud internet scams iPhone knol knowledge content Money mysql online purchase pagerank page rank PHP politics pr search engines SEO social media content social networks text browser themes web design web developer 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!