-
AuthorPosts
-
March 18, 2014 at 8:53 pm #239608
I’ve created a custom post type which uses “Category” as a taxonomy. When I select “News” as a category in the Latest News widget, no items are displayed. Probably because these items are from another post type. Is there a way to fix this?
March 19, 2014 at 10:52 am #239987Hey FotografieDuo!
You can define a new widget based on the existing newsbox widget. Insert this code:
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' ); } }
into your child theme functions.php or into enfold/functions.php and replace “portfolio_entries” with your custom taxonomy, “portfolio” with your custom post type, “Latest CPT” with your widget title/name.
Best regards,
PeterMarch 19, 2014 at 12:48 pm #240042Is it possible to do something similar with avia-shortcodes ?
Say add a custom avia-shortcode in the template builder based on let’s say “Portfolio Grid” but using a different CPT ?
Right now we’ve edited and created custom php files loading them using
add_filter('avia_load_shortcodes', 'avia_include_shortcode_template', 15, 1); function avia_include_shortcode_template($paths) { $template_url = get_stylesheet_directory(); array_unshift($paths, $template_url.'/shortcodes/'); return $paths; }
But they don’t benefit from the features you keep adding unless we edit our files manually.
March 19, 2014 at 2:42 pm #240067I’ve copied this code and pasted it in functions.php, but no new widget shows up in the widget area…
March 20, 2014 at 10:35 am #240615Hey!
Strange because it works on my test server. Please create me an admin account and I’ll check why the code doesn’t work.
Cheers!
PeterMarch 21, 2014 at 11:49 am #241110This reply has been marked as private.March 24, 2014 at 7:07 pm #242263Hi!
I created a child theme with the code. You can edit the widget code here: http://test.fotografieduo.com/wp-admin/theme-editor.php?file=functions.php&theme=enfold-child
I couldn’t get it to work with the parent theme though – I’m not sure why but maybe it’s because the child theme functions.php loads before the parent theme files.
Best regards,
PeterMarch 24, 2014 at 7:46 pm #242292Thanks Peter,
Maybe I found the anwser why I doesn’t work with the parent theme. Another customization I did, didn’t work the day before yesterday.
But yesterday it did, so somehow Ii suspect some files are cached (?). So I’ll have a good look at your code add it to the parent theme and wait a day so to see wheter or not the new widget shows up….I’ll keep you posted!
Best regards,
Arjan -
AuthorPosts
- The topic ‘Latest News widget: show custom post type’ is closed to new replies.