Theming listview to match category

Home Forums Welcome! Pre-Sales Questions Theming listview to match category

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1110176
    Svend Tveden-Nyborg
    Guest

    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

    #1110345
    Lasse
    Guest

    I 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

    #1110444
    Brook
    Participant

    Howdy 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

    #1113647
    Svend
    Guest

    Hi 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

    #1113987
    Brook
    Participant

    I 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

    #1114150
    Svend
    Guest

    Seems as if I was missing an echo in front of the do_shortcode. Guess that was the reason why the shortcode was not displayed as designed.

    Regards,

    Svend

    #1114494
    Brook
    Participant

    Oh that makes sense. I did not spot that either (yet). Thanks very much for sharing the solution!

    Cheers!

    – Brook

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Theming listview to match category’ is closed to new replies.