Change post template via url parameter
-
I needed to serve up the post content only.
Everything else, including the header, footer and the sidebars needed to be stripped out.
I needed this ‘post content only’ version to be always available, for every post, but for the original fully styled posts to be available as well.And I found this!!
http://scratch99.com/wordpress/development/how-to-change-post-template-via-url-parameter/I added the following code to my theme’s functions.php file:
function sjc_add_query_vars($vars) { return array('template') + $vars; } add_filter('query_vars', 'sjc_add_query_vars'); function sjc_template($template) { global $wp; if ($wp->query_vars['template']=='basic') { return dirname( __FILE__ ) . '/single-basic.php'; } else { return $template; } } add_filter('single_template', 'sjc_template');And I created a file called single-basic.php, then added the following code.
<div id="content"> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <h2 class="item"><span class="fn"><?php the_title(); ?></span></h2> <?php the_content(); ?> <?php endwhile; else: ?> <?php endif; ?> </div>But It didn’t work!
(http://domain.com/postname/?template=basic) is still blank page.
Please help me…
The topic ‘Change post template via url parameter’ is closed to new replies.