Home › Forums › Welcome! › Pre-Sales Questions › Theming listview to match category
- This topic has 6 replies, 1 voice, and was last updated 7 years, 11 months ago by Brook.
-
AuthorPosts
-
May 3, 2016 at 12:12 pm #1110176Svend Tveden-NyborgGuest
We want to theme a widget to match the event category with a page category – the aim is to be able to display events that match the current displayed page’s specific category.
We are aware of the widget “related-events.php” in which we for each widget need to setup what category/ies to display. This we want to do more dynamically.
In other words we would like to be able to loop through the events that match a specific code – can this be achieved?
Regards,
Svend Nyborg
May 4, 2016 at 2:49 am #1110345LasseGuestI believe the issue could be related to using code from the tribe-events-adv-list-widget. However, I am not an expert and have no hard core coding experience.
Regards,
Lasse
May 4, 2016 at 7:27 am #1110444BrookParticipantHowdy Svend Nyborg,
I would love to help you with this. It sounds to me like you have a set of WP Posts with their own categories, and each of those has an identically named event category with posts in it. On your Post pages you are hoping to a show a widget that will dynamically pull in all event categories with the same name. Is that correct?
If so then this would be very doable with Events Calendar Pro and a little bit of PHP coding. As Lasse said the Advanced List Widget could be used here. It has the ability to show only posts from a given categories. It also has a shortcode version that I think might be even more useful. That’s because you could do something like this with great ease:
<?php do_shortcode('[tribe_events_list category="'.$name_of_page_category.'"]');?>
And that would show any upcoming events that are in a category matching $name_of_page_category . Again though, it will require some PHP experience to get this all working and to make sure $name_of_page_category contains the date you need.
Does that all make sense? Will that work for you? Please let me know.
Thanks for helping out Lasse! Great idea with the Adv List widget.
Cheers!
– Brook
May 12, 2016 at 12:17 am #1113647SvendGuestHi Brook,
I like your code. However, when I insert the code into a custom widget plugin, I cannot make it work. What am I doing wrong?
<?php // WIDGET: Display related events class widget_disp_relatedevents extends WP_Widget { function __construct() { parent::__construct( // Base ID of your widget 'widget_disp_relatedevents', // Widget name will appear in UI __('Widget - Display Related events', 'wpb_widget_domain'), // Widget description array( 'description' => __( 'Custom widget displaying related events', 'wpb_widget_domain' ), ) ); } // Creating widget front-end public function widget( $args, $instance ) { // ****** TITLE OF WIDGET ****** $title = apply_filters( 'widget_title', $instance['title'] ); // before and after widget arguments are defined by themes echo $args['before_widget']; if ( ! empty( $title ) ) echo $args['before_title'] . $title . $args['after_title']; // ****** CONTENT ****** $cat_difficulty = array(); foreach((get_the_category()) as $childcat) { // Specific parent category (e.g. Post Cat ID=54) if (cat_is_ancestor_of(54, $childcat)) { // Everything is fine until now, and I can easily get the childname of the asked for parent category... do_shortcode('[tribe_events_list category="'.$childcat->cat_name.'"]'); } } echo $args['after_widget']; } // Updating widget replacing old instances with new public function update( $new_instance, $old_instance ) { $instance = array(); $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; return $instance; } } // WIDGET END // Register and load the widget function wpb_load_widget() { register_widget( 'widget_disp_relatedevents' ); } add_action( 'widgets_init', 'wpb_load_widget' ); /* Stop Adding Functions Below this Line */ ?>
The code works like a charm until I try to insert the code
do_shortcode('[tribe_events_list category="'.$childcat->cat_name.'"]');
.I hope you can assist me.
Regards,
Svend
May 12, 2016 at 12:16 pm #1113987BrookParticipantI would love to help you Svend. But would you mind logging in so I can verify your support access? If you just login with whatever account you purchased a support license with and respond here, that’s all I’ll need to continue.
Cheers!
– Brook
May 13, 2016 at 12:35 am #1114150SvendGuestSeems as if I was missing an
echo
in front of thedo_shortcode
. Guess that was the reason why the shortcode was not displayed as designed.Regards,
Svend
May 13, 2016 at 4:23 pm #1114494BrookParticipantOh that makes sense. I did not spot that either (yet). Thanks very much for sharing the solution!
Cheers!
– Brook
-
AuthorPosts
- The topic ‘Theming listview to match category’ is closed to new replies.