ThemeShaper Forums » Thematic

[closed]

Page Attributes (template selector) on Posts

(6 posts)
  • Started 2 years ago by mrmikeman
  • Latest reply from helgatheviking
  • This topic is not resolved
  1. mrmikeman
    Member

    Adding/Editing a "Page" I can select a template, (full width, etc) but on posts i cannot...

    i know on thesis framework there was a bit of code that displayed the page attributes for posts but how would it work for thematic?

    ps, id like to be able and display the same page attributes for custom post types too

    thanks!

    Posted 2 years ago #
  2. try the custom post templates plugin

    Posted 2 years ago #
  3. mrmikeman
    Member

    thatll be what i do if i cant get it figured out, id hope to be able and put something in my functions to allow it,
    on Thesis i did this:

    //add template metabox to posts
    function custom_no_sidebars_add_post_types_metaboxes() {
    	$args = array(
    		'public'   => true,
    		'_builtin' => false
    	);
    	$output = 'names';
    	$operator = 'and';
    	$post_types = get_post_types($args,$output,$operator);
    	$post_types['post'] = 'post';
    	foreach($post_types as $post_type => $label) {
    		add_meta_box( 'custom_no_sidebars_post_type_template_metabox', __('Template Selector'),'custom_no_sidebars_post_type_template_metabox', $post_type,'side','low');
    	}
    }
    add_action('add_meta_boxes', 'custom_no_sidebars_add_post_types_metaboxes');
    //save data function to store the meta info
    add_action('save_post', 'custom_no_sidebars_post_type_save_metadata');
    function custom_no_sidebars_post_type_save_metadata ($post_id) {
    	if ( !wp_verify_nonce( $_POST['custom_no_sidebars_metadata_noncename'], plugin_basename(__FILE__) ))
    		return $post_id;
    	if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
    		return $post_id;
    	if ( !current_user_can( 'edit_post', $post_id ) )
    		return $post_id;
    	// OK, we're authenticated: we need to find and save the data
    	$args = array(
    		'public'   => true,
    		'_builtin' => false
    	);
    	$output = 'names';
    	$operator = 'and';
    	$post_types = get_post_types($args,$output,$operator);
    	$post_types['post'] = 'post';
    	foreach($post_types as $post_type => $label) {
    		$data[$post_type] = array(
    				'_wp_page_template' => ''
    		);
    	}
    	$post_type = get_post_type($post_id);
    	$options = $data[$post_type];
    	if ($options) {
    		foreach($options as $option => $label) {
    			$value = $_POST[$option];
    			$current_value = get_post_meta($post_id, $option, $single = true);
    			if ($value && $value != $current_value) {
    				$check[$option] = update_post_meta($post_id,$option,$value);
    			} elseif (!$value && $current_value) {
    				$check[$option] = delete_post_meta($post_id,$option,$current_value);
    			}
    		}
    	}
    	return;
    }
    //template metabox for posts
    function custom_no_sidebars_post_type_template_metabox() {
    	wp_nonce_field( plugin_basename(__FILE__), 'custom_no_sidebars_metadata_noncename' );
    	$args = array(
    		'public'   => true,
    		'_builtin' => false
    	);
    	$output = 'names';
    	$operator = 'and';
    	$post_types = get_post_types($args,$output,$operator);
    	$post_types['post'] = 'post';
    	foreach($post_types as $post_type => $label) {
    		$data[$post_type] = array(
    				'default' => __('Default'),
    				'no_sidebars.php' => __('No Sidebars')
    		);
    	}
    	global $post;
    	$post_type = get_post_type($post->ID);
    	$keys = $data[$post_type];
    	if ($keys) {
    		$current_value = get_post_meta($post->ID, '_wp_page_template', $single = true);
    		echo '<select name="_wp_page_template" id="_wp_page_template">';
    		foreach($keys as $key => $label) {
    			$value = ($key == "default") ? '' : $key;
    			$selected_template = ($value == $current_value) ? ' selected="selected"' : '';
    			echo "<option id='$key' value='$value' $selected_template >$label</option>\n";
    		}
    		echo '</select>';
    		echo '<p class="description">'. __('You may choose the template here.') . "
    \n";
    	}
    }

    so i copy it over to thematic, i also make a full page template via page.php copy and put it in the code up there.. and the template selector DOES appear, but when i select Full Page, nothing changes..

    any idea? thanks!

    i used
    http://wptheming.com/2010/03/custom-page-templates-thematic/
    to make the full page width template. uhg im burning myself out again . .probably everyone else too ..

    Posted 2 years ago #
  4. posts don't use page templates, so selecting full-page doesn't do anything until you hook it up to something. i'm sure there is more to it that what you have. again, recommend the plugin. don't burn yourself out on something that has already been solved. that's the beauty of the WP community.

    Posted 2 years ago #
  5. mrmikeman
    Member

    so im finally getting back to this, and i went ahead and went the rout of the plugin :) so i got it working, the only thing is when i select the template for a post, the side bar which goes away, is now just an empty space.

    i know this is just a css thing but i cant remember or find how to target posts css that belong to a specific template.. know what i mean?

    thanks!

    Posted 2 years ago #
  6. dynamic body classes probably. use firebug to see the classes on the body tag. if you aren't using thematic's body classes i'm relatively certain that the plugin will add them. if you are, well you might have to filter in your own. dynamic body classes are something that gene and i are working on right now for the new release.

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.