Fork me on GitHub

Trick to Modifying Themes?  Bottom

  • Is there some trick to successfully changing code in a theme? It seems like most of the time when I've tried to make even the slightest changed in a theme (usually one thats loaded as the default theme), the whole site dies.. usually with some error about not finding themeheader, a parse error, or some other common error. I have to end up going into the database and manually resetting the default site theme to get the site back online. I've even chased some errors down by going line by line making changes on lines it specifies from the initial change but everytime I make a change, it seems to find another error farther down that wasn't there before. Is this typical, theme specific, or maybe I'm missing something? Do I need to change the default theme to something else that I'm not modifying while I'm making changes?
  • Same thing happened to me many times, before I changed to use the AutoTheme system. That is a bit more user friendly for amateurs like me.
  • You don't really need to know much PHP to mess w/ themes, but there are a couple of things you need to know inside out and be absolutely compulsive about: the echo statement, quoting rules (single vs double, & escaping quotes), and the concatenation operator (those periods you see all over). And of course making sure your semicolons are in the right places. When you start cutting & pasting snippets of theme code, this stuff invariably gets badly disarranged, so PHP barfs out raftloads of error messages over relatively trivial syntax errors (e.g. leftover semicolons embedded in concatenated echo strings). A single cut & paste is likely to leave syntax errors both where you cut & where you pasted, and those can add up to lots of fixes. On the bright side, they're easy to fix once you know what to look for.

    One thing that really helps is to use a text editor that has syntax coloring for PHP. That way, things will turn colors depending on whether they're quoted properly (or not), so you'll have immediate visual cues about whether your syntax is screwed up without having to throw the whole thing into the browser to test whether it works or not. I like to use Zend Studio (free version) since Zend is all about PHP, but there are excellent general-purpose text editors for geeks on every platform.

    General purpose hint: if you're not quite clear on how a particular theme formats each page, make a duplicate copy of it, and go thru and give each & every table two additions
    1) a couple of pixels of border width
    2) a different & vivid border color.
    Then look at it in your browser, and see how all the pieces stack together. This will also help you avoid mangling the tables when you re-arrange stuff.

    If you really don't get how PN themes work, you might also want to insert echo statements at the beginning and end of each function, which say stuff like 'themesidebox() called here' and 'themesidebox returns here'. Looks even uglier than rainbow table borders, but does wonders for figuring out how the theme works. Three hints: use single quotes! also, in themeheader, be sure to put this inside the body tag, and in general, these statements must be inside of TD's (not TR's) or they won't show up.

    Finally, you will soon notice that most of the themes one downloads have been ported and patched so many times they're a real thicket of random echo statements. I find that it helps to go thru the theme first, and clean it up a bit before starting to change it around. It's good practice in writing valid PHP echo statements, and also helps me get to know the theme so I can edit it more intelligently. In the process, you can also make the them output readable HTML, which can be a major help when debugging.

    Re: AutoTheme
    I think it's really cool, a truly nifty bit of coding... but it also causes a really noticeable performance lag if you compare it side by side with a hard-coded theme. Postnuke is a large enough mass of code that it already takes a noticeable bit of time to generate a page, and adding another layer of code to the theming process slows it down even more. And if one knows (or wants to learn) PHP, themes are pretty straightforward... at least once you learn to see all of those niggling syntax errors before you feed them to a browser.
  • Thanks noelvn!

    AutoTheme is costly, code execution wise. I have re-written the command parse replace code in the commercial 1.0 and will this week finish the GPL Lite version with the same code enhancement.

    It shows much faster. Let me know!

    Thanks!
    Shawn
  • Even bette than having to learn PHP and remember to escape quotes, knowing when to use the dot character for echo statements, remembering semicolons, etc, wasting server time parsing code that simply gets sent to the browser, and not being able to SEE the damn thing in a WYSIWYG editor, is to write the damn theme in HTML!!! with embedded PHP. That's how PHP was designed, after all!! There's a reason it's called an EMBEDDED scripting language. You just escape to PHP whenever you actually NEED it, like at thge beginning and end of a function, API calls, etc. That way, you can SEE what you're doing in Dreamweaver, don't have to do the HTML and then recode it into PHP. Stupid way of doing it, frankly. cry :x :!: :!:
  • I have to disagree with the various posts that suggest that folks should be working in HTML with embedded PHP or Autothemes. It's true that these approaches will help a newbie in the short term.

    But these approaches will fail in the long-term. No matter how much everyone wants to think otherwise, PostNuke is a PHP application that generates its output encoded in HTML. It is not an HTML application that calls embedded PHP scripts. A real theme designer must understand how PN works and how the themeheader() and themefooter() calls relate to modules so that they can construct themes that will work. There are plenty of other reasons why you need to work in PHP and they become obvious once you read the source.

    You can argue all you want but until you bite the bullet and learn enough PHP to code a theme, you will continue to have problems and your themes will have problems.
  • I agree you need to understand PHP in order to properly design a theme, but no need to make it harder than it has to be. I understand PHP reasonably well, enough to get around and debug code. I also understand how the theme works, and know the most common API functions and variables being used (like $index, $info and $preformat), although by no means am I a real hacker. I'm a designer, and I think visually. I just don't see the need for all those 'echo' statements with escaped quotes presented in a near-unreadable format. In my themes, I've converted most of them to HTML with embedded PHP, as it ought to be, properly indented for readability. Everything is still embedded in PHP functions, but now you're able to see it in Dreamweaver. I like PHP, it's a great scripting language, and I would probably prefer it there to some Smarty template with predefined Smarty-tags, whatever they are. I don't know a lot about Smarty, which they're gonna use in the upcoming theme overhaul, I'm just worried about a performance hit in the system having to parse the template with regular expressions. Also I worry about losing flexibility in inserting PHP functions to some set list.

    I would like other parts of the system improved for the designer, such as proper use of classes and ID tags in the called API functions, rather than too-generic classes like PN-normal etc, which means changing one will change all, unless you do some fancy CSS footwork, and even then you can't fix all the problems. In ColdRolledSteel's theme, MTModular, there are places (like Members List) where the type is unreadable because it's the same color as the background, because it draws on set background and text colors in the theme and stylesheet, and there's no easy way of fixing just the text on that page without affecting text elsewhere. :D
  • ColdRolledSteel, you couldn't be more wrong... PHP was implicity designed to be embedded into HTML, as this quote on the homepage of php.net so aptly states:

    Quote

    What is PHP?
    PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

    Those echo statements are totally unnecessary and in fact, slow the processing of the theme down. *Especially* when using double quotes, as this forces PHP to parse *everything* in the echo statement looking for variables. (Plus you have to escape the double quotes). If you insist on coding like this, use single quotes, please...

    msandersen, I couldn't have said it better. Themes ought to have been designed so that HTML is coded as HTML and PHP is coded as PHP. Unfortunately, I think many folks followed the somewhat bad examples of the included PN themes... PHP vars, like the story name, hits, etc... can easily be inserted into HTML with the shorthand:

    Code

    <?= $variablename ?>


    (Note: no semicolon. P.S. You must have short tags enabled in your php.ini for that syntax to work (which most setups do). Otherwise, use

    I have made a "Starter Theme" and a short tutorial for how themes ought to be written here:
    http://forums.postnu…&t=18177&highlight=

    Scroll down the page somewhat for more "Tips" (the posters got a little off-topic)
    The theme should be such that you can paste it's components into DW or any good HTML editor for easier editing - or at the very least, for easy editing withing your text editor...

    --
    Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

    Cape Cod Travel Info...

This list is based on users active over the last 60 minutes.