WordPress.org

Ideas

Post Templates

  1. Vincent Mimoun-Prat
    Member

    12345

    nmallory : I have developed just what you have been looking for :

    http://www.vincentprat.info/wordpress/2007/03/01/wordpress-plugin-post-templates/
    or
    http://wordpress.org/extend/plugins/post-template/

    Posted: 11 years ago #

  2. Inactive

    I am new to WP though REALLY in love with it. As i am discovering the different features in WP, one thing in the text editor that I notice is that it is not capable of Text Wrap. I uploaded images but it either stays above, below, or takes its own entire row whereever i placed the image. In other words, the text doesn't wrap around the image.

    Is there a plugin out there to compliment this built-in text editor?

    Posted: 10 years ago #
  3. Vincent Mimoun-Prat
    Member

    12345

    Just to note that the Post Template plugin has moved to: http://www.vincentprat.info/dev/post-templates/

    It addresses precisely the functionnality you were looking for.

    Posted: 10 years ago #
  4. DouglasVB
    Member

    12345

    I would like to see the plugin http://www.vincentprat.info/dev/wordpress-plugins/post-templates/ integrated into the wordpress core. If we can have page templates, why can't we have post templates?

    Posted: 10 years ago #

  5. Inactive

    I downloaded and applied the post-templates plug-in.
    http://www.vincentprat.info/dev/post-templates/

    It works - but isn't exactly what I was hoping for as I can not make a change in the template file and have it go back to posts made with the template. I still manually have to go back and make those changes.

    I now have to show my editors the HTML tags in hopes they will be able to fix things when they start putting things on the page (it's really easy for them to start their content inside the submenu color box that I put in the template). We'll see how it goes. If it were just me doing the pages this plug-in would be easy to use - but my editors are new at doing anything on the web.

    The plug-in works well though - it's a good start. I guess what I need is a post-template that works more like an include statement.

    Thanks.
    June

    Posted: 9 years ago #
  6. petroski
    Member

    Hello,

    I'm using a customized version of WordPress that implements post templates in the same way that templates works for pages. I'm using it for Real Estate websites but this functionality will work in many other environments.

    If interested, see http://wp-realestate.com for a real world demo of post templates as well as the actual code changes required to implement this. The code changes shown apply to WP 2.6 (may work on later versions but has not been implemented or tested) and the demo website is running WP 2.5.1 The original code changes were originally developed by Giovanni Marques Costa who has a website at http://iferrari.net/. I know that Giovanni submitted this modification to WordPress Trac (#7103) for consideration for inclusion. Unfortunately, there has not been further activity on his original posting since July 2008.

    Additionally, there appears to be a plug-in based on Giovanni's modification which I have downloaded and will test - will post here as to the results.

    :-)

    Posted: 9 years ago #
  7. DanF89
    Member

    12345

    Petroski,

    The site wp-realestate.com seems to be down. Would you mind sharing how to create the post template functionality to mimic the page template function?

    Thanks,
    -Daniel

    Posted: 9 years ago #
  8. petroski
    Member

    @DanF89

    Sorry Daniel, I lied - the website address is actually http://wp-realestate.ca

    I downloaded a plugin called wp-post-skin which simplifies the whole process and does not require extensive code rework every time you upgrade to a new version of WordPress. You can see that in action at http://lifestyleproperties.ca. I will be updating http://wp-realestate.ca with this new plugin in the near term. See the code below - file name is wp-post-skin.php. Sorry about the file comments, I'm not sure what language it is.

    <?php
    /*
    Plugin Name: wp-post-skin
    Version: 0.1
    Plugin URI: http://blog.thedezine.com/pro/?p=1661
    Description: Based on the post template idea by Giovanni Marques Costa.
    Author: Kaloyan K. Tsvetkov
    Author URI: http://kaloyan.info/
    */
    
    /**
    * Podmeni single.php s naznachenia template
    */
    Function get_post_template($template) {
    	global $post;
    
    	$template_wannabe = get_post_meta(
    		$post->ID, '_wp_post_template', true
    		);
    
    	if ( 'default' == $template_wannabe ) {
    		$template_wannabe = '';
    		}
    
    	if ( !empty($template_wannabe) && !validate_file($template_wannabe) && file_exists(TEMPLATEPATH . "/$template_wannabe") ) {
    		$template = TEMPLATEPATH . "/$template_wannabe";
    		} 
    
    	return $template;
    	}
    add_filter('single_template', 'get_post_template');
    
    /**
    * Kato se wika w templejtite moje da se razbere dali si w (post) templejt ili ne ... wtf ?!
    */
    Function is_single_template($template = '') {
    
    	if (!is_single()) {
    		return false;
    		}
    
    	global $wp_query;
    
    	$post = $wp_query->get_queried_object();
    	$custom_fields = get_post_custom_values('_wp_post_template', $page->ID);
    	$post_template = $custom_fields[0];
    
    	// We have no argument passed so just see if a post_template has been specified
    	if ( empty( $template ) ) {
        		if (!empty( $post_template ) ) {
        			return true;
        			}
        		} else {
        		if ( $template == $post_template) {
        			return true;
        			}
        		}
    
    	return false;
    	}
    
    /**
    * kato se zapiswat dannite, zapischi i ti izbrania post template
    */
    Function save_post_template($post_ID, $post) {
    
    	$post_template = @$_REQUEST['post_template'];
    
    	if ( !empty($post_template) && 'post' == $post->post_type ) {
    		if ( 'default' != $post_template && !in_array($post_template, get_page_templates()) ) {
    			return;
    			}
    		update_post_meta($post_ID, '_wp_post_template', $post_template);
    		}
    	}
    add_action('save_post', 'save_post_template', 10, 2);
    
    /**
    * Kutijkata za redaktiraneto na postovete
    */
    Function post_template_meta_box($post) { ?>
    	<label class="hidden" for="post_template"><?php _e('Post Template') ?></label>
    
    	<select name="post_template" id="post_template" style="width: 100%;">
    		<option value='default'><?php _e('Default Template'); ?></option>
    		<?php
    		$default = get_post_meta($post->ID, '_wp_post_template', 1);
    		$templates = get_page_templates();
    		ksort( $templates );
    		foreach (array_keys( $templates ) as $template ) {
    			if ( $default == $templates[$template] ) {
    				$selected = " selected='selected' ";
    				} else {
    				$selected = '';
    				}
    			echo "\n\t<option value='". $templates[$template], "' $selected >$template (", basename($templates[$template]), ")</option>";
    			};
    		?>
    		</select>
    
    	<p><?php _e('Some themes have custom templates you can use for
    			certain posts that might have additional features
    			or custom layouts. If so, you will see them above.'); ?></p>
    	<?php
    	}
    
    /**
    * Ako w izbranata tema ima templejti, izpolzwaj gi
    */
    Function admin_post_templates($post = null) {
    
    	if ( get_page_templates()) {
    		add_meta_box(
    			'post_template_div',
    			__('Post Templates'),
    			'post_template_meta_box',
    			'post', 'advanced', 'core'
    			);
    		}
    	}
    add_action('edit_form_advanced', 'admin_post_templates'); ?>
    Posted: 9 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.

  • Rating

    12345
    135 Votes
  • Status

    This is plugin territory