Substitute template on custom field?
-
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…
- The topic ‘Substitute template on custom field?’ is closed to new replies.