• Hi,

    Any help much appreciated (a lengthy search and review of past issues didn’t help) — I’ve got a WordPress site that I’m using to source both an HTML newsletter and a straight blog, which serves as the archive of the newsletter (each WordPress post is a single newsletter).

    I’ve got a custom version of single.php in my theme folder, single_nl.php, that I’ve coded to strip out everything but what I want my mailer program to grab to send as the HTML email.

    I use custom fields to figure out which is the current newsletter post and render it in “straight” HTML (no divs, minimal styles, etc.) for nice display in a wide range of web-based email environments.

    The custom field is parsed by get_post_meta() and if I find the field (‘newsletter’) I include my custom single_nl.php page in TEMPLATEPATH.

    This renders fine, the problem is that the regular version of single.php renders immediately beneath it (or index.php if I pull single.php out). How do I explicitly replace the standard template, in this case single.php, with my template such that it stops rendering when my page is done? Is there a way to exclude files from TEMPLATEPATH on a case-by-case basis? What am I doing wrong?

    I’m calling get_post_meta() from header.php (which is _not_ included in single_nl.php):

    <?php if( is_single() &&  get_post_meta($post->ID, 'newsletter', true) ) {
      include(TEMPLATEPATH . '/single_nl.php');
    } ?>

    Again, thanks for any help…

Viewing 3 replies - 1 through 3 (of 3 total)
  • what you’re doing looks correct, check to see if sidebar or footer.php (may as well check header, etc as well) is making a call to load the single.php file, it looks like that’s what’s happening after sidebar_nl is loaded.

    Thread Starter vmixer

    (@vmixer)

    Thanks for taking a look at my php code. None of the included files (either upstream or downstream) are calling the regular version of single.php, so I think this is just the loop doing what it does.

    I think it may be a better idea to either handle this via a theme switcher, where I can append something to the permalink URL (actually probably the query string), or via a per-post style plugin to render a given post using my “lite” template.

    Thread Starter vmixer

    (@vmixer)

    Just to close the loop — I ended up using a version of the Theme Preview plugin (from https://dougal.gunters.org/blog/2005/03/09/theme-preview-plugin/ ) to accomplish this. This seems to work well, and doesn’t involve publishing an inconsistent version of the post to the site in order to make the newsletter version. I tried 1 or 2 other versions of Theme Preview, but the above was the only one that worked for me under 2.1.3. This is the Dougal Campbell version.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Substitute template on custom field?’ is closed to new replies.