Posted by brook123, 11-22-2012, 11:03 PM | I'm trying to get wordpress to add a sidebar for each post of a custom post type. Can anyone provide code for this?
Looking forward to our replies
|
Posted by spydoo, 11-22-2012, 11:36 PM | php get_sidebar(); ?>
If you want to use a different sidebar you'll have to use "include".
Have a look at http://codex.wordpress.org/Customizing_Your_Sidebar for all about this.
Good luck with your custom theme.
|
Posted by deydod, 11-23-2012, 07:16 AM | There are a lot different ways to achieve this, but here is a little how-to:
1) in function.php add register_sidebar functions with different "name" parameter.
Example:
Place as many as you want.
2) Create custom single-.php in the template folder. You can just duplicate the single.php for this demo.
3) Lets say your post type is "cars", they you should have a file called single-cars.php. Edit this file and change:
to
4) That's it. When you open your custom post type then the desired sidebar should show up.
Deyan
|
Posted by Alex Northen, 11-25-2012, 01:06 AM | Hello,
In functions.php we would use the register_post_type WordPress function to create the sidebar content post type.
__('Sidebar Content'),
'singular_name' => __('Sidebar Entry'),
'add_new' => __('Add New'),
'add_new_item' => __('Add New Sidebar Entry'),
'edit_item' => __('Edit Sidebar Entry'),
'new_item' => __('New Sidebar Entry'),
'view_item' => __('View Sidebar Entry'),
'search_items' => __('Search Sidebar Entry'),
'not_found' => __('No Sidebar Entry found'),
'not_found_in_trash' => __('No Sidebar Entry found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => true,
'menu_position' => null,
'supports' => array('title','editor','author', 'page-attributes', 'revisions')
);
register_post_type('sidebar-content',$args);
}
?>
|
Posted by SimonDevise, 01-10-2013, 06:30 AM | Hi . I have used plugin that allow to set sidebar for each post category , so you can manage sidebar for each custom post just giving to each post a new category . Here is that plugin - wordpress.org/extend/plugins/custom-sidebars .
|
|
Add to Favourites
Print this Article |