Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #368315

    I’m using this code to create a new widget to show a CPT (I replaced ‘portfolio_entries with my custom taxonomy and portfolio with the CPT)

    add_action(‘after_setup_theme’,’avia_load_additional_widget’);
    function avia_load_additional_widget()
    {
    if (!class_exists(‘avia_customcptbox’))
    {
    class avia_customcptbox extends avia_newsbox
    {
    function avia_customcptbox()
    {
    $this->avia_term = ‘portfolio_entries’;
    $this->avia_post_type = ‘portfolio’;
    $this->avia_new_query = ”; //set a custom query here
    $widget_ops = array(‘classname’ => ‘newsbox’, ‘description’ => ‘A Sidebar widget to display latest cpt entries in your sidebar’ );

    $this->WP_Widget( ‘customcptbox’, THEMENAME.’ Latest CPT’, $widget_ops );
    }
    }

    register_widget( ‘avia_customcptbox’ );
    }
    }

    It works fine as long as I only create one additional widget. When I duplicate the code for a different CPT, my widget.php stops functioning.
    Which changes do I have to make to create a second widget?

    #369273

    Hi Arjan de Wit!

    Thank you for using Enfold.

    You can try this on functions.php:

    add_action('after_setup_theme','avia_load_additional_widget');
    function avia_load_additional_widget() {	
    	// portfolio
    	if (!class_exists('avia_customcptbox_portfolio')) {
    		class avia_customcptbox_portfolio extends avia_newsbox {
    		function avia_customcptbox_portfolio() {
    			$this->avia_term = 'portfolio_entries';
    			$this->avia_post_type = 'portfolio';
    			$this->avia_new_query = ''; //set a custom query here
    			$widget_ops = array('classname' => 'newsbox', 'description' => 'A Sidebar widget to display latest portfolio entries in your sidebar' );
    			
    			$this->WP_Widget( 'customcptbox_portfolio', THEMENAME.' Latest CPT Portfolio', $widget_ops );
    			}	
    		}
    		register_widget( 'avia_customcptbox_portfolio' );
    	}
    
    	// post
    	if (!class_exists('avia_customcptbox_post')) {
    		class avia_customcptbox_post extends avia_newsbox {
    		function avia_customcptbox_post() {
    			$this->avia_term = 'category';
    			$this->avia_post_type = 'post';
    			$this->avia_new_query = ''; //set a custom query here
    			$widget_ops = array('classname' => 'newsbox', 'description' => 'A Sidebar widget to display latest post entries in your sidebar' );
    			
    			$this->WP_Widget( 'customcptbox_post', THEMENAME.' Latest CPT Post', $widget_ops );
    			}	
    		}
    		register_widget( 'avia_customcptbox_post' );
    	}
    }

    This will show entries for portfolio items and default post type.

    Best regards,
    Ismael

    #369884

    Hi,

    Haven’t tried it yet but I have no doubt this will work!
    I can see what I’ve been doing wrong.

    Best regards,
    Arjan

    #369908

    Hi!

    We will keep the thread open. Please try it and let us know.

    Cheers!
    Yigit

    #369922

    Hi,

    It works!

    Best regards,
    Arjan

    #369928

    I was wondering: would it be difficult to add another widget to Enfold that is similar to the Latest News widget but
    shows posts based upon a specific tag? Maybe I should make this a feature request?

    #369965

    Hi!

    Not sure if i understood correctly but to me it sounds like you can use Tag Cloud widget. If not, please request it here – https://kriesi.at/support/enfold-feature-requests/
    You can search for a plugin as well.
    Cheers!
    Yigit

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