-
AuthorPosts
-
December 15, 2014 at 4:02 pm #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?December 17, 2014 at 1:45 am #369273Hi 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,
IsmaelDecember 18, 2014 at 9:37 am #369884Hi,
Haven’t tried it yet but I have no doubt this will work!
I can see what I’ve been doing wrong.Best regards,
ArjanDecember 18, 2014 at 12:25 pm #369908December 18, 2014 at 12:59 pm #369922Hi,
It works!
Best regards,
ArjanDecember 18, 2014 at 1:09 pm #369928I 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?December 18, 2014 at 3:20 pm #369965Hi!
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 -
AuthorPosts
- You must be logged in to reply to this topic.