12 Aug

integrating wordpress with smarty (continued)

Mostly, everything in the integration of wordpress and Donncha’s Smarty code had already been done – i just needed to figure out why little errors were creeping in.
The first I tackled was one where posts appeared with mangled titles on the front site. After a bit of grepping, I found that it was the template command {the_category} that was screwing up.
An example of the screw up was:
<a href="?cat=0" http://verens.com/index.php?cat="1&quot;" title="Category: &lt;a href=">General</a>"&gt;[<a href="http://verens.com/index.php?cat=1" title="View all posts in General">General</a>]
That one, while it took some time to find the cause, was a cinch to fix – simply delete everything in the wp-blogs/main/templates_c/ directory! Next time you view the page it’ll be much better…
…but not perfect – what appears as {the_author} in the template was displayed as “kaekae” in the front – the username doubled. A bit of code-searching and testing revealed that the_author() was returning ‘kaekae’ via $authordata->user_nickname.
I thought I had it when I tracked it down to get_userdata() in wp-include/functions.php, but a bit of testing revealed that the if conditional never became true – for some reason $cache_userdata[$userid] was not empty.
After much frustration, I finally noticed that the second parameter of the_author() was $echo = true, which triggered an echo of the user id in that function, doubling the output as the call from the template also printed it to screen.
I changed the true to false, then went looking for calls to that function to make sure they worked fine.
In wp-atom.php, wp.php and wp-rdf.php, I changed instances of <?php the_author() ?> to <?php echo the_author() ?>, and removed the second parameter and associated code from the function.
It is my considered opinion that the second parameter was a stupid idea which merely saved a few bytes of typing by the programmers. It is always a bad idea to directly echo a function’s return value from within that function, unless that is the purpose of the function.

3 thoughts on “integrating wordpress with smarty (continued)

  1. Pingback: Holy Shmoly! :: Smarty and WP, again

  2. Wow, Good work finding that lot! I really have to setup CVS and an account for you and we’ll get Smarty templates in there working perfectly!

  3. I fixed that function, and others another way – there was a bug in my create_smarty_template.php script – it didn’t handle default args properly. I’ll send you on a copy of it tonight.
    Then, in post.html, change {the_author} to {the_author echo=false}
    Now clear your cached templates and reload your blog!
    Although it impacts the Smarty template, at least it doesn’t require a change to the original WP PHP code. That’s handy when we’re trying to track changes from one WP version to the next.

Comments are closed.