Archived topic
Override Settings
3 replies · Started by Mouring Kolhoff on May 22, 2015
Hi Tom,
I have a site with several post types, the public can add content to them via a frontend, so no access to the backend.
Depending on the posttype I would like to show either no sidebars, one sidebar or two sidebar.
For me to go into every entry to set the settings according to that posttype after some added data is a bit of a headache. Is there a way to set on a post type basis the layout required.
Absolutely, we can set the page layout using a function and a filter, as seen in some examples here: http://generatepress.com/knowledgebase/choosing-sidebar-layouts/
For you, you could do something like this:
add_filter( 'generate_sidebar_layout','generate_custom_post_type_sidebar_layout' );
function generate_custom_post_type_sidebar_layout( $layout )
{
// Get post type
$type = get_post_type();
// If our post type is named "my_post_type", set the sidebar
if ( 'my_post_type' == $type )
return 'both-left';
// If our post type is named "recipes", set the sidebar
if ( 'recipes' == $type )
return 'left-sidebar';
// Or else, set the regular layout
return $layout;
}
How to add PHP: http://generatepress.com/knowledgebase/adding-php-functions/
Hope this helps :)
Thanks Tom,
This is working 100%
Keep up the good work
Thanks! :)
