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

    • Everything has changed… again..
    • Looking back at 2009
    • Word Wrap on Eclipse
    • Google Adwords Pending/Under Review
    • Excited for my new internet connection
  • Recent Comments

    • lopau: yey my ad has finally been approved. For the record that was 54 hours since submission.
    • lopau: @magnus tnx for the additional info. @mr. backlink. lucky you, my ad isn’t approved yet, it’s...
    • Mr. Backlinks: Hmmmm…. I just launched a campaign and it was instantly approved. Although, a friend of mine is...
    • Magnus Nilsson: I’ve noticed increasingly delays in approval recently, think its due to all retailers changing...
    • Mayank: I am facing the same problem on my couple of production domains. Lets see which of these solutions works for...
    • cleopatra costumes: Many thanks for the info. I almost freaked out, thinking someone had hacked my wordpress and...
  • 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
    • 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

    • 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
  • Tags

    Adsense among ed 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 virtualization 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!