Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #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,
    Neverlands

    #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.

    #784732

    Hi 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; 
    }
    #784744

    try

    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 ;-)

    #784762

    Hi mensmaximus,

    many thanks, but this doesn’t change anything

    #784791

    For 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, 6 months ago by mensmaximus. Reason: removed debug code :-)
    #784815

    Hi 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.

    #784817

    OK 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;
    }
    
    #784824

    Hi!

    Please do let us know if you try it and it works for you, the code seems to be valid as a reply

    Cheers!
    Basilis

    #784825

    Hello mensmaximus and Basilis,

    the solution works perfectly!

    Thanks alot and best regards,
    Neverlands

    #785323

    Hi Neverlands,

    Glad we could help :)

    If you need further assistance please let us know.
    Best regards,
    Victoria

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.