-
AuthorPosts
-
April 28, 2017 at 4:26 pm #784679
I bought the Encyclopedia Pro plugin.
I managed to enable the Advanced Layout Editor for the Encyclopedia post type:add_filter('avf_builder_boxes', 'add_builder_to_posttype'); function add_builder_to_posttype($metabox) { foreach($metabox as &$meta) { if($meta['id'] == 'avia_builder' || $meta['id'] == 'layout') { $meta['page'][] = 'encyclopedia'; /*instead add the name of the custom post type here*/ } } return $metabox; }
My question is, if it is possible to add a specific sidebar (“Glossar”) to all Encyclopedia posts at once.
We have more than 350 Encyclopedia posts an it would be much work to add the sidebar manually.At default all sidebars are deactivated through the Enfold theme settings.
Best regards,
NeverlandsApril 28, 2017 at 5:10 pm #784715@neverlands there is a filter called ‘avf_custom_sidebar’. The filter gets the passed the sidebar ($sidebar). It should (didn’t try it myself) be possible to hook into the filter query the post_type (encyclopedia) and the status of the sidebar (empty($sidebar)) and if both conditions match return the sidebar you desire.
April 28, 2017 at 5:36 pm #784732Hi mensmaximus,
thanks for your reply!
I tried this but it doesn’t work:add_filter('avf_custom_sidebar','add_sidebar_to_posttype'); function add_sidebar_to_posttype($sidebar) { if( $post_type == 'encyclopedia' ) { $sidebar = "Glossar"; } return $sidebar; }
April 28, 2017 at 6:12 pm #784744try
add_filter('avf_custom_sidebar','add_sidebar_to_posttype'); function add_sidebar_to_posttype($sidebar) { global $post; if( $post->post_type == 'encyclopedia' && empty($sidebar) ) { $sidebar = "Glossar"; } return $sidebar; }
Caution! It is untested an just edited in here without syntax check (just from my brain ;-)
April 28, 2017 at 6:45 pm #784762Hi mensmaximus,
many thanks, but this doesn’t change anything
April 28, 2017 at 8:08 pm #784791For me this is working out of the box as expected.
I installed Encyclopedia Lite plugin, Enfold and an Enfold Child Theme. I activated the Child Theme. I added a new widget area named ‘glossar’ under appearance -> widgets. I put a text widget in this new sidebar an gave it the title ‘Glossar Test’. I opened my favorite text editor (ultraedit) and put in the following code:
add_filter('avf_builder_boxes', 'add_builder_to_posttype'); function add_builder_to_posttype($metabox) { foreach($metabox as &$meta) { if($meta['id'] == 'avia_builder' || $meta['id'] == 'layout') { $meta['page'][] = 'encyclopedia'; } } return $metabox; } add_filter('avf_custom_sidebar','add_sidebar_to_posttype'); function add_sidebar_to_posttype($sidebar) { global $post; if( $post->post_type == 'encyclopedia' && empty($sidebar) ) { $sidebar = "glossar"; } return $sidebar; }
I went to the lexicon in wp-admin and created a new entry called ‘Test’. In the sidebar metabox i changed nothing. All selectboxes show default.
I called the new entry in a browser and my glossar sidebar with the glossar test widget gets displayed.
In the global enfold sidebar settings the right sidebar is active.
- This reply was modified 7 years, 7 months ago by mensmaximus. Reason: removed debug code :-)
April 28, 2017 at 9:26 pm #784815Hi mensmaximus,
propably this makes the difference.
As I mentioned in the beginning, sidebars are deactivated in the Enfold Child theme settings, because I don’t use them anywhere else.April 28, 2017 at 9:32 pm #784817OK so we need one function more. And as we are at it we add the lexicon posttype to the blog grid, portfolio and masonry element
add_theme_support( 'add_avia_builder_post_type_option' ); add_theme_support( 'avia_template_builder_custom_post_type_grid' ); add_filter('avf_builder_boxes', 'add_builder_to_posttype'); function add_builder_to_posttype($metabox) { foreach($metabox as &$meta) { if($meta['id'] == 'avia_builder' || $meta['id'] == 'layout') { $meta['page'][] = 'encyclopedia'; } } return $metabox; } add_filter('avf_custom_sidebar','select_widget_area_for_encyclopedia'); function select_widget_area_for_encyclopedia($sidebar) { global $post; if( $post->post_type == 'encyclopedia' && empty($sidebar) ) { $sidebar = "glossar"; } return $sidebar; } add_filter('avia_layout_filter', 'select_sidebar_for_encyclopedia', 10, 2); function select_sidebar_for_encyclopedia( $layout, $post_id ){ $post_type = get_post_type( $post_id ); $sidebar = get_post_meta( $post_id, 'layout', true ); /* * possible choices for $default: * 'left' for sidebar on the left side * 'right' for sidebar on the right side * anything else or empty for fullwidth layout with no sidebar */ $default = 'right'; if( $post_type == 'encyclopedia' && empty($sidebar) ) { switch ($default) { case 'left': $layout['current']['content'] = 'av-content-small'; $layout['current']['sidebar'] = 'alpha'; $layout['current']['meta'] = 'alpha'; $layout['current']['main'] = 'sidebar_left'; break; case 'right': $layout['current']['content'] = 'av-content-small alpha'; $layout['current']['sidebar'] = 'alpha'; $layout['current']['meta'] = 'alpha'; $layout['current']['main'] = 'sidebar_right'; break; default: $layout['current']['content'] = 'alpha'; $layout['current']['sidebar'] = 'hidden'; $layout['current']['meta'] = ''; $layout['current']['main'] = 'fullsize'; } } return $layout; }
April 28, 2017 at 10:05 pm #784824Hi!
Please do let us know if you try it and it works for you, the code seems to be valid as a reply
Cheers!
BasilisApril 28, 2017 at 10:09 pm #784825Hello mensmaximus and Basilis,
the solution works perfectly!
Thanks alot and best regards,
NeverlandsApril 30, 2017 at 5:38 pm #785323Hi Neverlands,
Glad we could help :)
If you need further assistance please let us know.
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.