• So, I love the whole themes concept; it works great and all, but I do have one (small) issue with it. If I make modifications to a theme—the sidebar for instance—by adding in non WP-managed links, links to Bloglines, or whatever; in order for these to be persistent across multiple themes (if I wanted to provide several themes for my users to choose between), I would have to duplicate this code across every available theme and update it in each theme package everytime I wanted to make a change.

    Code duplication is Bad ™ So what can be done about this? Any solutions that jump to mind? I suppose I need a file that stores custom adjustments to a WP template that exists independently of the theme structure, but that each theme can call on at will.

    That sounds great, but I wouldn’t know where to begin, my knowledge of the WP architecture being shaky at best. Any suggestions?

Viewing 15 replies - 1 through 15 (of 18 total)
  • I’d say making all your themes use the same CSS structure then you can call via php one central sidebar.php file.
    <?php include="https://example.com/sidebar.php" ?>

    Why not include an include ‘path/interesting_addition.php’? You’ll have to include this once in every theme, but afterwards it doesn’t need to be updated anymore.

    Thread Starter danweasel

    (@danweasel)

    Sounds good; thanks. Curse my php skills not being up to par.

    Not a problem. ??

    Thread Starter danweasel

    (@danweasel)

    Hmm…

    Of course, that would remove the ability to edit sidebar.php from within the Presentation page of the WP admin, right?

    Yep it would. I don’t use that though, I like having two copies of my pages, one on my hdd, and one on my web server. I always FTP everything.

    You could try keeping the sidebar in only one theme dir, and having the others include it, pointing it to that sole location. That way, whatever theme your on, you can go to the theme manager and select the theme with the sidebar in it’s directory. Changes will apply to all themes.

    However, you could do this.

    make a new theme folder in ~/wp-content/themes/, and put your static pages in there, then call them
    <?php include "https://example.com/wp-content/
    themes/static/sidebar.php" ?>

    -desk003

    We said the same thing, however I did not know because I was typing it when you posted and you were typing it when I was reading his reply. lmao. ??

    If you want different themes to share one set of templates, you can have stylesheet-only themes inherit templates from a base theme.

    Let’s say you want to create a theme that inherits templates from the default theme. This theme would contain only a style.css and perhaps an alternate set of images. To have this stylesheet-only theme pick up templates from the default theme, include the following in the theme header in style.css:

    Template: default

    This tells the theme system to use the templates provided in the wp-content/themes/default directory.

    Too good to be true, Ryan. You’re awesome.

    Thread Starter danweasel

    (@danweasel)

    So…if I killed everything from the default theme directory except sidebar.php, I could then use the get_sidebar() function in other themes, leave sidebar.php out of them, and they would pick up (by something like inheritance?) the sidebar.php from the default template?

    Do I have that right?

    You can’t pick and choose certain files to inherit, you must inherit a full set of templates. It’s an all or nothing deal. For awhile we did allow individual inheritance, but it confused the hell out of people and was a bit too heavyweight during page load since the code had to go looking in multiple locations in order to put a theme together. That’s why I call themes that inherit templates from other themes “stylesheet only” themes. They don’t have any templates of their own.

    Thread Starter danweasel

    (@danweasel)

    So if all I want to keep constant throughout different themes is one page (sidebar.php), which option is better: delete everything from the default directory except my version of sidebar.php (basically hacking default so that it is no longer a theme, but more an “abstract class” in Java terminology) or explicitly including sidebar.php from a newly created “static” theme as desk003 suggests?

    By the way, template loading is fully pluggable. There are filter hooks called category_template, single_template, page_template, etc. Through a plugin, template loading can be completely customized. You can implement full inheritance or even pull templates out of the database.

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Duplicative Templates’ is closed to new replies.