Conditional to display add event button in sidebar

Home Forums Calendar Products Community Events Conditional to display add event button in sidebar

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #933000
    jewschool
    Participant

    Hi,

    I’m trying to create a conditional to display a button in my sidebar linking to the community event submission form.

    I’m using the following code to invoke the button, but it doesn’t seem to be working. Am I missing something? Am I using the wrong conditionals?

    if is_page('events') || tribe_is_event() {
     echo '<center><a class="button-st button-with-icon button-with-icon-16 ico-st ico-plus button-custom-color" href="/events/community/add" target="_parent" style="background-color: #16a085;"><span>Submit an Event</span></a></center>';
     };
    #933290
    Barry
    Member

    Hi Benjamin,

    You generally ought to wrap the conditional in parentheses:

    if ( is_page('events') || tribe_is_event() ) { /*...*/ }

    Please also note that event views are not actually pages in the traditional WordPress sense (they are not editable posts stored in the database) so if that first test – is_page(‘events’) – is trying to detect requests for the main events page it won’t work (though if you happen to have an actual WordPress page called events and that is one of the things you are looking for then of course it’s completely fine).

    I hope that helps 🙂

    #933388
    jewschool
    Participant

    Duh, I can’t believe I forgot the parens.

    That said: Is there another conditional I can se to check if it’s the main calendar page?

    #933415
    Barry
    Member

    None built in that specifically do just that, but you could potentially use a custom function like this one (modify to suit your needs!):

    /**
     * Returns true if the current page is the main events page, else returns
     * false.
     *
     * Criteria for the "main events page" here means:
     *
     *     - We're on an events page
     *     - It is the same view as the default events view
     *     - No particular date has been specified
     * 
     * @return bool
     */
    function is_main_events_page() {
    	global $wp_query;
    
    	// We needn't worry about non-event requests
    	if ( ! tribe_is_event_query() ) return false;
    
    	// Get the default view and currently requested view
    	$default = TribeEvents::instance()->default_view();
    	$current = $wp_query->get( 'eventDisplay' );
    
    	// Was a date specifically set? If so, it isn't truly the "main" events page
    	$date_set = $wp_query->get( 'eventDate' ) . isset( $_REQUEST['tribe-bar-date'] ) ? 1 : 0;
    
    	// Compare and contrast!
    	return ( $default === $current && ! $date_set );
    }
    #938792
    Barry
    Member

    Hi! It’s been a while so I’m going to go ahead and close this thread. If we can help with anything else, though, please don’t hesitate to create new threads as needed. Thanks!

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Conditional to display add event button in sidebar’ is closed to new replies.