Store WordPress post template in PHP var / Heredoc / Nowdoc?
-
I have a relatively large post template, using a whole variety of different PHP variables and WordPress functions. Now the problem is that as the site has grown larger, the need for slightly different methods of displaying posts have arisen, but beyond their wrapper functions they still use the post template. (One is a just vanilla, one is a shortcode and one is a Ajax function)
So when I updated one, I have to roll the same changes out to the other two templates, which beyond feeling incredibly silly also goes against DRY. So my question is, is there a way to store a WordPress post template in a variable that can be easily called or put into a WP Query? Would a Heredoc / Nowdoc variable work for the purpose?
For the sake of argument let’s say this is my template:
<div class='post-wrapper' id='post-<?php the_id(); ?>' > <div class='thumbnail-wrapper'> <?php if(is_user_logged_in()): the_post_thumbnail("full"); else: echo $login_prompt; endif; ?> </div> </div>Thanks in advance!
-
Hi there.
I’m afraid you’re in the wrong forum. This support forum is only for free WordPress.com blogs, and we can’t use JavaScript, access the PHP files or create our own post templates here, so you most likely have a self-hosted WordPress.ORG install. WordPress.com and WordPress.org are completely separate and different: http://en.support.wordpress.com/com-vs-org/
Please visit the WordPress.org support forum for assistance as we won’t be able to help you here: http://wordpress.org/support/ If you don’t already have a username on that forum, click the register button in the upper right corner so you can post in that forum.
- The topic ‘Store WordPress post template in PHP var / Heredoc / Nowdoc?’ is closed to new replies.