WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Template
[resolved] Custom Post Template drop down Menu no longer appears with wordpress 3.4 (17 posts)

  1. riversatile
    Member
    Posted 2 years ago #

    Hi,

    "Custom Post Template" drop down Menu no longer appears with wordpress 3.4. I think the plugin's author have to update the plugin.

    The new/edit post form displays the message :
    This theme has no available custom post templates.

    Thanks for your supports

    http://wordpress.org/extend/plugins/custom-post-template/

  2. riversatile
    Member
    Posted 2 years ago #

    I saw this post on the web :
    http://stackoverflow.com/questions/11027121/page-templates-disappeared-with-wordpress-3-4

    Apparently from 3.4 the "Template Name" comment needs to look like this:
    
    /*
        Template Name: MyCustomTemplate
    */
    
    Hope this helps somebody else.
  3. riversatile
    Member
    Posted 2 years ago #

    But apparently, this solution doesn't work for me... :-(
    I have to manually add the custom field "custom_post_template"

  4. UltraLinx
    Member
    Posted 2 years ago #

    I've been having the same problem too ever since updating to WordPress 3.4.

    I can't have full width posts anymore which is highly annoying.

    Anyone know how to fix it?

  5. riversatile
    Member
    Posted 2 years ago #

    The author of the plugin Simon wheatley has released an upgrade for WordPress 3.4, but it doesn't solve this issue !

  6. UltraLinx
    Member
    Posted 2 years ago #

    I just updated to the newest version and it's fixed it for me.

    Hopefully you'll find a fix for your problem!

  7. riversatile
    Member
    Posted 2 years ago #

    I'm french, so my WordPress is in french.
    Perhaps this is the issue...

    fortunately, I can use custom fields ;)

  8. Simon Wheatley
    Code for the People
    Plugin Author

    Posted 2 years ago #

    @riversatile: Can you post just the header from one of your templates, please? NOT the whole template.

  9. riversatile
    Member
    Posted 2 years ago #

    @Simon Wheatley: The issue in located in the Admin Dashboard, not on my theme templates.
    Is my template headers will really help you ?

  10. riversatile
    Member
    Posted 2 years ago #

    I found the issue, here I saw 1 people that said to replace :

    /*
        Template Name Posts: MyCustomTemplate
    */

    by

    /*
        Template Name: MyCustomTemplate
    */

    But he was wrong !
    I put back :

    /*
        Template Name Posts: MyCustomTemplate
    */

    And now it's working !!!!!!!!!!

    Thanks guys

  11. Simon Wheatley
    Code for the People
    Plugin Author

    Posted 2 years ago #

    Good to hear, thank you. Where did you see that advice, please?

    Cheers,

    Simon

  12. riversatile
    Member
    Posted 2 years ago #

    Here : http://stackoverflow.com/questions/11027121/page-templates-disappeared-with-wordpress-3-4

    But I missunderstood that the guy told about "Custom Page template" and not about "Custom Post Template" !

  13. veinbmx
    Member
    Posted 1 year ago #

    I've installed this plugin and it seems to be working (my full-width template shows in the template dropdown menu) but after selecting it and updating the post, it is still appearing as the default layout for posts? Something must be overriding this plugin right? Any suggestions?

  14. Amy_Beth
    Member
    Posted 1 year ago #

    Go to Post Template and select "Snarfer." That is what worked for me.

  15. veinbmx
    Member
    Posted 1 year ago #

    Excuse my ignorance but what do you mean by "select" Snarfer? And are you refering to the "Custom Post Template" accessable in WordPress Admin or are you talking about the template I needed to make and upload via FTP(Full Width Template)?
    I don't see that in either code. Here's the code I've been looking at. Any help will be much appreciated.

    Also here's a link to a post page example still not taking the full-width setting: http://www.amberbmx.com/?p=601

    <?php
    /**
     *  Template Name Posts: Full Width Posts
     *
     * Full width page template with no sidebar.
     *
     * @package Oxygen
     * @subpackage Template
     */
    get_header(); // Loads the header.php template. ?>
    	<div class="aside">
    		<?php get_sidebar( 'primary' ); // Loads the sidebar-primary.php template. ?>
    	</div>
    	<?php do_atomic( 'before_content' ); // oxygen_before_content ?>
    	<div class="content-wrap">
    		<div id="content">
    			<?php do_atomic( 'open_content' ); // oxygen_open_content ?>
    			<div class="hfeed">
    				<?php if ( have_posts() ) : ?>
    					<?php while ( have_posts() ) : the_post(); ?>
    						<?php do_atomic( 'before_entry' ); // oxygen_before_entry ?>
    						<div id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">
    							<?php do_atomic( 'open_entry' ); // oxygen_open_entry ?>
    							<?php echo apply_atomic_shortcode( 'entry_title', '[entry-title]' ); ?>
    							<div class="entry-content">
    								<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'oxygen' ) ); ?>
    								<?php wp_link_pages( array( 'before' => '<p class="page-links">' . __( 'Pages:', 'oxygen' ), 'after' => '</p>' ) ); ?>
    							</div><!-- .entry-content -->
    							<?php echo apply_atomic_shortcode( 'entry_meta', '<div class="entry-meta">[entry-edit-link]</div>' ); ?>
    							<?php do_atomic( 'close_entry' ); // oxygen_close_entry ?>
    						</div><!-- .hentry -->
    						<?php do_atomic( 'after_entry' ); // oxygen_after_entry ?>
    						<?php do_atomic( 'after_singular' ); // oxygen_after_singular ?>
    					<?php endwhile; ?>
    				<?php endif; ?>
    			</div><!-- .hfeed -->
    			<?php do_atomic( 'close_content' ); // oxygen_close_content ?>
    		</div><!-- #content -->
    		<?php do_atomic( 'after_content' ); // oxygen_after_content ?>
    <?php get_footer(); // Loads the footer.php template. ?>
    <?php
    /*
    Plugin Name: Custom Post Templates
    Plugin URI: http://wordpress.org/extend/plugins/custom-post-template/
    Description: Provides a drop-down to select different templates for posts from the post edit screen. The templates are defined similarly to page templates, and will replace single.php for the specified post.
    Author: Simon Wheatley
    Version: 1.5
    Author URI: http://simonwheatley.co.uk/wordpress/
    */
    /*  Copyright 2008 Simon Wheatley
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */
    require_once( dirname (__FILE__) . '/plugin.php' );
    require_once( dirname (__FILE__) . '/template-tags.php' );
    /**
     *
     * @package default
     * @author Simon Wheatley
     **/
    class CustomPostTemplates extends CustomPostTemplates_Plugin
    {
    	private $tpl_meta_key;
    	private $post_ID;
    	function __construct()
    	{
    		// Init properties
    		$this->tpl_meta_key = 'custom_post_template';
    		// Init hooks and all that
    		$this->register_plugin ( 'custom-post-templates', __FILE__ );
    		// NOTE TO PEOPLE WANTING TO USE CUSTOM POST TYPES:
    		// Don't edit this file, instead use the cpt_post_types filter. See the plugin description
    		// for more information. Thank you and good night.
    		$this->add_action( 'admin_init' );
    		$this->add_action( 'save_post' );
    		$this->add_filter( 'single_template', 'filter_single_template' );
    		$this->add_filter( 'body_class' );
    	}
    	/*
    	 *  FILTERS & ACTIONS
    	 * *******************
    	 */
    	/**
    	 * Hooks the WP admin_init action to add metaboxes
    	 *
    	 * @param
    	 * @return void
    	 * @author Simon Wheatley
    	 **/
    	public function admin_init() {
    		// NOTE TO PEOPLE WANTING TO USE CUSTOM POST TYPES:
    		// Don't edit this file, instead use the cpt_post_types filter. See the plugin description
    		// for more information. Thank you and good night.
     		$post_types = apply_filters( 'cpt_post_types', array( 'post' ) );
    		foreach ( $post_types as $post_type )
    			$this->add_meta_box( 'select_post_template', __( 'Post Template', 'custom-post-templates' ), 'select_post_template', $post_type, 'side', 'default' );
    	}
    	/**
    	 * Hooks the WP body_class function to add a class to single posts using a post template.
    	 *
    	 * @param array $classes An array of strings
    	 * @return array An array of strings
    	 * @author Simon Wheatley
    	 **/
    	public function body_class( $classes ) {
    		if ( ! is_post_template() )
    			return $classes;
    		global $wp_query;
    		// We distrust the global $post object, as it can be substituted in any
    		// number of different ways.
    		$post = $wp_query->get_queried_object();
    		$post_template = get_post_meta( $post->ID, 'custom_post_template', true );
    		$classes[] = 'post-template';
    		$classes[] = 'post-template-' . str_replace( '.php', '-php', $post_template );
    		return $classes;
    	}
    	public function select_post_template( $post )
    	{
    		$this->post_ID = $post->ID;
    		$template_vars = array();
    		$template_vars[ 'templates' ] = $this->get_post_templates();
    		$template_vars[ 'custom_template' ] = $this->get_custom_post_template();
    		// Render the template
    		$this->render_admin ( 'select_post_template', $template_vars );
    	}
    	public function save_post( $post_ID )
    	{
    		$action_needed = (bool) @ $_POST[ 'custom_post_template_present' ];
    		if ( ! $action_needed ) return;
    		$this->post_ID = $post_ID;
    		$template = (string) @ $_POST[ 'custom_post_template' ];
    		$this->set_custom_post_template( $template );
    	}
    	public function filter_single_template( $template )
    	{
    		global $wp_query;
    		$this->post_ID = $wp_query->post->ID;
    		// No template? Nothing we can do.
    		$template_file = $this->get_custom_post_template();
    		if ( ! $template_file )
    			return $template;
    		// If there's a tpl in a (child theme or theme with no child)
    		if ( file_exists( trailingslashit( STYLESHEETPATH ) . $template_file ) )
    			return STYLESHEETPATH . DIRECTORY_SEPARATOR . $template_file;
    		// If there's a tpl in the parent of the current child theme
    		else if ( file_exists( TEMPLATEPATH . DIRECTORY_SEPARATOR . $template_file ) )
    			return TEMPLATEPATH . DIRECTORY_SEPARATOR . $template_file;
    		return $template;
    	}
    	/*
    	 *  UTILITY METHODS
    	 * *****************
    	 */
    	protected function set_custom_post_template( $template )
    	{
    		delete_post_meta( $this->post_ID, $this->tpl_meta_key );
    		if ( ! $template || $template == 'default' ) return;
    		add_post_meta( $this->post_ID, $this->tpl_meta_key, $template );
    	}
    	protected function get_custom_post_template()
    	{
    		$custom_template = get_post_meta( $this->post_ID, $this->tpl_meta_key, true );
    		return $custom_template;
    	}
    	protected function get_post_templates()
    	{
    		$theme = wp_get_theme();
    		// N.B. No caching, even though core Page Templates has that.
    		// Nacin advises:
    		// "ultimately, "caching" for page templates is not very helpful"
    		// "by default, the themes bucket is non-persistent. also, calling
    		//  get_page_templates() no longer requires us to load up all theme
    		//  data for all themes so overall, it's much quicker already."
    		$post_templates = array();
    		$files = (array) $theme->get_files( 'php', 1 );
    		foreach ( $files as $file => $full_path ) {
    			$headers = get_file_data( $full_path, array( 'Template Name Posts' => 'Template Name Posts' ) );
    			if ( empty( $headers['Template Name Posts'] ) )
    				continue;
    			$post_templates[ $file ] = $headers['Template Name Posts'];
    		}
    		return $post_templates;
    	}
    }
    /**
     * Instantiate the plugin
     *
     * @global
     **/
    $CustomPostTemplates = new CustomPostTemplates();
    ?>
  16. Amy_Beth
    Member
    Posted 1 year ago #

    I am using a Template from Elegant Templates. After I installed the plugin, I went to one of the posts, scrolled over to where it says: "Post Template," and it gave me two options: default template and snarfer. Snafer is what I picked. Also, make sure that you have a custom field with the name: custom_post_template
    and the value: fullwidth-post.php

    Hope this helps.

  17. veinbmx
    Member
    Posted 1 year ago #

    Oh okay, I have the option for this post template. Mine is just named "Full Width Posts".
    Where do I put this "custom field"? In one of the templates I posted above? Or somewhere else?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic